C#: Statements and Methods Based on slides by Joe Hummel.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Introduction to Programming
Chapter 8: Arrays.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Language Fundamentals in brief C# - Introduction.
C#: Udtryk og metoder. Indhold “With regards to programming statements and methods, C# offers what you would come to expect from a modern OOPL…” Udtryk.
Chapter 10 Introduction to Arrays
Loops (Part 1) Computer Science Erwin High School Fall 2014.
C#: Data Types Based on slides by Joe Hummel. 2 UCN Technology: Computer Science Content: “.NET is designed around the CTS, or Common Type System.
Introduction to the C# Programming Language for the VB Programmer.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
C# Programming: From Problem Analysis to Program Design1 Arrays C# Programming: From Problem Analysis to Program Design 3 rd Edition 7.
Arrays. A group of data with same type stored under one variable. It is assumed that elements in that group are ordered in series. In C# language arrays.
C# Programming: From Problem Analysis to Program Design1 Repeating Instructions C# Programming: From Problem Analysis to Program Design 3rd Edition 6.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
4. Statements and Methods. 2 Microsoft Objectives “With regards to programming statements and methods, C# offers what you would come to expect from a.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
CSCI 130 for Loops Chapter 7 - A. Execution of a C Program Execution starts in main( ) Top down style –sequential flow Unrealistic to expect sequence.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
The Ruby Programming Language
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
1 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.
Advanced Programming LOOP.
FEN 2012 UCN Technology: Computer Science1 C# - Introduction Language Fundamentals in Brief.
Spring 2007NOEA: Computer Science Programme 1 C# - Introduction Language Fundamentals: Data Types string Objects and Classes Methods Iteration and Selection.
C# Intro Programming languages and programs: Source code and object code Editors and compilers C# fundamentals: Program structure Classes and Objects Variables.
Crypto Project Sample Encrypted Data: –Turing: CS Public\CryptoProjectData Crypto_Short_Keys_P_U.out Crypto_Long_Keys_O_R.out Bonus +10 points on.
Iteration (Loop) partI Thanachat Thanomkulabut. Consider the following program! using System; Namespace SimPleExample { class SimPleC { class SimPleC.
Java ProgrammingtMyn1 Java Programming Timo Mynttinen Mikkeli University of Applied Sciences.
Loops Repeating Code Multiple Times SoftUni Team Technical Trainers Software University
Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
1 Advanced Programming IF. 2 Control Structures Program of control –Program performs one statement then goes to next line Sequential execution –Different.
1 nd Semester Module7 Arrays Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
C# Programming Fundamentals Control Flow Jim Warren, COMPSCI 280 S Enterprise Software Development.
CSCI 171 Presentation 4. Execution of a C Program Execution starts in main( ) Top down style –sequential flow Unrealistic to expect sequence in more complicated.
Processing Sequences of Elements Technical Trainer Telerik Corporation Doncho Minkov.
DT249-Information Systems Research Practice Programming Revision Lecture 2 Lecturer: Patrick Browne.
Methods SWE 344 Internet Protocols & Client Server Programming.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Section 3 - Arrays and Methods. Arrays Array: collection of group of data variables of same type, sharing the same name for convenience - Easy to search.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Final Review Author: Thanachat Thanomkulabut Edited by Supaporn Erjongmanee Final Review 22 September 2011.
Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline Counter-Controlled Repetition: Example Sentinel-Controlled Repetition:
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
1 Statements © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License.
1 Advanced Programming Examples. using System; class Test { static void Main( string[] args ) { int a = 7; int b = 3; int c = 5; int d = 9; Console.WriteLine(!(d.
Repeating Code Multiple Times
Repetition (While-Loop) version]
Unit-1 Introduction to Java
C++ Programming: CS150 For.
Controlling execution - iteration
Compiler Design First Lecture.
Chapter 8: Control Structures
11/10/2018.
Structured Program Development in C
Module8 Multi-dimensional Array
The structure of programming
CSE 1020:Software Development
Thanachat Thanomkulabut
Iteration (Loop) part II
Presentation transcript:

C#: Statements and Methods Based on slides by Joe Hummel

2 UCN Technology: Computer Science – 2014 Contents “With regards to programming statements and methods, C# offers what you would come to expect from a modern OOPL…” Statements Methods

3 UCN Technology: Computer Science – 2014 Part 1 Statements

4 UCN Technology: Computer Science – 2014 Statements in C# Assignments Sub routines and functions Conditionals –if, switch Iteration –for, while, do-while (Uncontrolled) Control Flow –return, break, continue, goto

5 UCN Technology: Computer Science – 2014 Examples x = obj.foo(); if (x > 0 && x < 10) count++; else if (x == -1)... else {... } while (x > 0) {... x--; } for (int k = 0; k < 10; k++) {... }

6 UCN Technology: Computer Science – 2014 Other Statements C# also includes… –iteration over a data structure (Collection) using foreach –namespace imported using using

7 UCN Technology: Computer Science – 2014 foreach Specialised foreach loop for sweeping through collections, e.g. array –Reduces the risk for indexing errors –Allows only read only access to elements int[] data = { 1, 2, 3, 4, 5 }; int sum = 0; foreach (int x in data) { sum += x; } foreach typevaluecollection

8 UCN Technology: Computer Science – 2014 using using directive provides access to classes in a namespace without pre-fixing // before Workshop.Customer c; c = new Workshop.Customer("joe hummel", 94652); //after using Workshop; Customer c; c = new Customer("joe hummel", 94652); namespace Workshop { public class Customer {. } public class Product {. }

9 UCN Technology: Computer Science – 2014 Example using directives in the top of the file /* main.cs */ using System; using Workshop; public class App { public static void Main() { Customer c; c = new Customer("joe hummel", 94652); Console.WriteLine( c.ToString() ); } namespace Workshop { public class Customer {. } public class Product {. }

10 UCN Technology: Computer Science – 2014 Part 2 Methods…

11 UCN Technology: Computer Science – 2014 Types of methods Classes may define 2 types of methods: –instance –static Instance methods can only be applied to instances (objects) of the class. So an object must be created before the method can be used. Static methods may be called using the class name

12 UCN Technology: Computer Science – 2014 Example The Array class in FCL –fully-qualified name is System.Array namespace System { public class Array { public int GetLength(int dimension) {... } public static void Sort(Array a) {... }. } instance method (no static modifier) static method (static modifier)

13 UCN Technology: Computer Science – 2014 Method call Method call (Array class): /* main.cs */ using System; public class App { public static void Main() { int[] data = { 11, 7, 38, 55, 3 }; Array.Sort(data); for (int i=0; i<data.GetLength(0); i++) Console.WriteLine(i + ": " + data[i]); }

14 UCN Technology: Computer Science – 2014 Other static methods that may come handy… using System; public class Calculator { public static void Main() { string input, output; int a, b, sum; Console.Write("Enter first integer: "); input = Console.ReadLine(); a = Convert.ToInt32(input); Console.Write("Enter second integer: "); input = Console.ReadLine(); b = Convert.ToInt32(input); sum = a + b; output = String.Format("{0} + {1} = {2}", a, b, sum); Console.WriteLine(output); } Adding two integers and printing the sum:

15 UCN Technology: Computer Science – 2014 Summing Up All the usual statements (known from Java), and a few new ones –assignment, if, for, while, foreach, using Two types of methods –instance methods, needs an object –static methods, may be called on the class