Presentation is loading. Please wait.

Presentation is loading. Please wait.

Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.

Similar presentations


Presentation on theme: "Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays."— Presentation transcript:

1 Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays

2 Operators & Constructs & Arrays / Session2 / 2 of 42 Module 1 – Review (1) .Net Framework is multi-language platform to build, deploy and run various types of applications  Two major components of.Net Framework is CLR and FCL  When code is written in.Net language such as C#,VB…compiled, output code is converted to code native to operating system by Just-In-Time language

3 Operators & Constructs & Arrays / Session2 / 3 of 42 Module 1 – Review (2)  C# is an object-oriented programming language derived from c and C++.  C# support features like type-safety checking, garbage collection, ECMA standardization, generics  Visual studio 2005 is complete set of tool to build high performance applications

4 Operators & Constructs & Arrays / Session2 / 4 of 42 Module 2 – Review (1)  In C#, data types are also divided into two categories: value types and reference types  The predefined data types are referred to as basic data types in C#.  C# supports three types of comments  XML comments are inserted in XML tags. These tags can either be predefined or user- defined.

5 Operators & Constructs & Arrays / Session2 / 5 of 42 Module 2 – Review (2)  Two output methods: Console.Write() and Console.WriteLine()  Two input methods: Console.Read() and Console.ReadLine()  Convert class is used to convert a variable into another data type.  Some type of format specifiers: number and datatime

6 Operators & Constructs & Arrays / Session2 / 6 of 42 Module 3 - Objectives  List the statement categories in C#  Identify and explain the use of operators  Explain Boxing and Unboxing

7 Operators & Constructs & Arrays / Session2 / 7 of 42 Types of Statements  Selection  Iteration  Jump  Exception Handling  Checked and Unchecked  Fixed statement  Lock statement

8 Operators & Constructs & Arrays / Session2 / 8 of 42 Selection Statements  if - else  switch - case  Tenary or conditional operator ? : ;

9 Operators & Constructs & Arrays / Session2 / 9 of 42 Iteration Statements  do  for  foreach, in  while

10 Operators & Constructs & Arrays / Session2 / 10 of 42 Jump Statements  break  continue  default  goto  return  yield

11 Operators & Constructs & Arrays / Session2 / 11 of 42 Exception Handling  try  catch  finally

12 Operators & Constructs & Arrays / Session2 / 12 of 42 Checked and Unchecked statements  The checked statement checks for an arithmetic overflow in arithmetic expressions.  An arithmetic overflow occurs if the result of an expression or a block of code is greater than the range of the target variable’s data type.  When overflow, an exception OverflowException is thrown

13 Operators & Constructs & Arrays / Session2 / 13 of 42 Checked and Unchecked Statements using System; class Addition { public static void Main() { byte numOne = 255; byte numTwo = 1; byte result = 0; try { // This code throws an overflow exception checked { result = (byte)(numOne + numTwo); } Console.WriteLine("Result: " + result); } catch(OverflowException ex) { Console.WriteLine(ex); }

14 Operators & Constructs & Arrays / Session2 / 14 of 42 Operators  Arithmetic Operators: +, -, *, /, %  Relational Operators: ==, !=, >, =  Logical Operators: &&, ||, ^, &, |  Increment and Decrement Operators: ++, - -  Assignment Operators: +=, -= …  Shift Operators: >  String Concatenation Operator: +  Ternary or Conditional Operator: exp1 ? exp2 : exp3

15 Operators & Constructs & Arrays / Session2 / 15 of 42 Type casting  C# support two types of casting: implicit explicit

16 Operators & Constructs & Arrays / Session2 / 16 of 42 Implicit Type Casting

17 Operators & Constructs & Arrays / Session2 / 17 of 42 Explicit Type Casting  Explicit typecasting refers to changing a data type of higher precision into a data type of lower precision

18 Operators & Constructs & Arrays / Session2 / 18 of 42 Explicit Type Conversion  Two other ways to implement explicit type conversion Convert class ToString() method

19 Operators & Constructs & Arrays / Session2 / 19 of 42 Boxing and Unboxing  Using Boxing and Unboxing, a value of any value type can be converted to a reference type and vice-versa  When any value-type is boxed, its value is copied into a new object and the reference to that object is stored.  This new object is stored on the heap

20 Operators & Constructs & Arrays / Session2 / 20 of 42 Boxing  object o = i;  object o = (object)i;

21 Operators & Constructs & Arrays / Session2 / 21 of 42 Unboxing  int i = (int)o;

22 Operators & Constructs & Arrays / Session2 / 22 of 42 Module 3 - Summary

23 Operators & Constructs & Arrays / Session2 / 23 of 42 Module 4 - Objectives  State the syntax and working… case statement  State the syntax and working of for loop  Describe the go to statement  Describe the break and continue statements

24 Operators & Constructs & Arrays / Session2 / 24 of 42 The switch Statement Syntax switch(variable) { case value: //Statements break; case value: //Statements break; default: //Statements break; }

25 Operators & Constructs & Arrays / Session2 / 25 of 42 The switch Statement – Contd… switch(weekday) { case 1: Console.WriteLine (“You have selected Monday”); break; case 2: Console.WriteLine (“You have selected Tuesday”); break; default: Console.WriteLine (“Sunday is the Default choice!”); break; }

26 Operators & Constructs & Arrays / Session2 / 26 of 42  The while loop iterates through the specified statements till the condition specified is true  Syntax – The while loop The break statement - to break out of the loop at anytime The continue statement - to skip the current iteration and begin with the next iteration

27 Operators & Constructs & Arrays / Session2 / 27 of 42 Examples using System; class TestLoop { static void Main() { int intRes, intCnt = 1; while (intCnt <= 10) { intRes = intCnt * 5; Console.WriteLine("{0}",intRes); intCnt = intCnt+1; }

28 Operators & Constructs & Arrays / Session2 / 28 of 42 The do loop Syntax -

29 Operators & Constructs & Arrays / Session2 / 29 of 42 The for loop Syntax -

30 Operators & Constructs & Arrays / Session2 / 30 of 42 Jump Statements

31 Operators & Constructs & Arrays / Session2 / 31 of 42 The “break,continue,goto,return “ statements

32 Operators & Constructs & Arrays / Session2 / 32 of 42 Module 4 - Summary

33 Operators & Constructs & Arrays / Session2 / 33 of 42 Module 5 - Objectives  State the syntax of declaring arrays  Describe Array class and its purpose  List the commonly properties and methods in Array class

34 Operators & Constructs & Arrays / Session2 / 34 of 42 DataType[number of elements] ArrayName; int[6] array1; Arrays  A group of values of similar data type  Belong to the reference type and hence are stored on the heap  The declaration of arrays in C# follow the syntax given below -

35 Operators & Constructs & Arrays / Session2 / 35 of 42 Single-Dimensional Array

36 Operators & Constructs & Arrays / Session2 / 36 of 42 Multi-Dimensional Array

37 Operators & Constructs & Arrays / Session2 / 37 of 42 foreach Statement  The foreach loop in C# is an extension of the for loop.  This loop is used to perform specific actions on collections, such as arrays. foreach(type in ) { // statements }

38 Operators & Constructs & Arrays / Session2 / 38 of 42 Sample

39 Operators & Constructs & Arrays / Session2 / 39 of 42 Array Class  The Array class is built-in class in the System namespace and is the base class for all arrays in C#  It provides methods for various tasks such as creating, searching, copying and sorting arrays.

40 Operators & Constructs & Arrays / Session2 / 40 of 42 Array Class Properties

41 Operators & Constructs & Arrays / Session2 / 41 of 42 Array Class Methods

42 Operators & Constructs & Arrays / Session2 / 42 of 42 Module 5 - Summary


Download ppt "Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays."

Similar presentations


Ads by Google