Software Development  Training Program KaZIM HUSSAIn
Operators <ul><li>Operators can be used to combine or alter the program values. There are three types of operators: - </li...
Unary Operators <ul><li>Unary Operators are that operators which require one operand to perform calculation. </li></ul><ul...
Increment and Decrement Operator The ++ and – are increment and decrement operators. The increment operator increases its ...
Increment and Decrement Operator <ul><li>The expression  </li></ul><ul><li>a = a + 1; </li></ul><ul><li>can written using ...
Increment and Decrement Operator <ul><li>The operator a++ first assign the value and then increment a by one. </li></ul><u...
Examples Initial value of a Expression Final value of b Final value of a 5 b  =  a++ 5 6 5 b  =  ++a 6 6 5 b  =  a-- 5 4 5...
Bitwise Inversion Operator <ul><li>This operator performs bitwise inversion on integral types. This operator works by conv...
Bitwise Inversion Operator <ul><li>For example binary representation : </li></ul><ul><li>01001101 </li></ul><ul><li>Using ...
Bitwise Inversion Operator <ul><li>For a positive value the result is always negative and increase the value by one. </li>...
Bitwise Inversion Operator <ul><li>For a negative value the result is always positive and decrease the value by one. </li>...
Boolean Complement Operator <ul><li>The ! Operator inverts the value of a boolean expression. So  </li></ul><ul><li>!true ...
Binary Operators <ul><li>Binary Operators   are that operators which require two operand to perform calculation. </li></ul...
Binary Operators Comparison Operator Bitwise Operators Short Circuit Logical Operators & ^ | < <= > >= == != is as && ||
Binary Operators Assignment Operators = *= /= % = += -= & = ^= |=
Arithmetic Operators <ul><li>Basic arithmetic operators are addition(+),  subtraction(-), multiplication(*), and division(...
Comparison Operator <ul><li>These are also called relational operators. They determine the relationship that one operand h...
Comparison Operator Operator Result == Equal to != Not equal to >  Greater than <  Less than >= Greater than or equal to <...
Bitwise Operator <ul><li>The bitwise operators provides bitwise AND, XOR and OR operations respectively. These operators c...
Bitwise Operator (&) <ul><li>For AND operation 1 AND 1 results 1. any other combination produces 0. </li></ul>Op1 Op2 Op1 ...
Bitwise Operator (|) <ul><li>For OR operations, 0 OR 0 produces 0. any other combination produces 1. </li></ul>Op1 Op2 Op1...
Bitwise Operator (^) <ul><li>For XOR operations, 1 XOR 0 produces 1, as 0 XOR 1 does, any other combination produces 0. </...
Bitwise Operator <ul><li>The &,^ and | behave in the same way when applied to boolean. </li></ul>
Bitwise Operator (&) <ul><li>For AND operation true AND true results true. any other combination produces false. </li></ul...
Bitwise Operator (|) <ul><li>For OR operations, false OR false produces false. any other combination produces true. </li><...
Bitwise Operator (^) <ul><li>For XOR operations, true XOR false produces true, as false XOR true does, any other combinati...
Short Circuit Logical Operators <ul><li>The short circuit logical operators && and || provide logical AND and OR operation...
Short Circuit Logical Operators <ul><li>For an AND operation, if first operand is false, the result is false without check...
Example <ul><li>int a = 5; </li></ul><ul><li>bool b = (  (a>8)  &&   (a==5)  ); </li></ul><ul><li>The first expression (a>...
Example <ul><li>int a = 5; </li></ul><ul><li>bool b = (  (a>3)  | |   (a==2)  ); </li></ul><ul><li>The first expression (a...
Assignment Operators = *= /= % = += -= & = ^=
Example <ul><li>int a = 6; </li></ul><ul><li>int b = 7; </li></ul><ul><li>a += b; result  a=13 </li></ul><ul><li>a *= b; r...
Ternary Operators <ul><li>Ternary Operators   are that operators which require three operands to perform calculation. Ther...
Example <ul><li>int a = 5; </li></ul><ul><li>int b = a == 5 ? 6 : 1; </li></ul><ul><li>result b = 6; </li></ul><ul><li>boo...
Operator Precedence <ul><li>Precedence </li></ul><ul><li>Associativity </li></ul>
Operator Precedence Category Operators Primary (x)  x.y  f(x)  a[x]  x++  x--  new  typeof  sizeof  checked  unchecked Una...
Examples <ul><li>int a = 9; </li></ul><ul><li>int b = 12; </li></ul><ul><li>int c = a & b +   a | b; </li></ul><ul><li>res...
Examples <ul><li>int a = 9; </li></ul><ul><li>int b = 12; </li></ul><ul><li>int c = a & b +  ( a | b ) ; </li></ul><ul><li...
Examples <ul><li>int a = 9; </li></ul><ul><li>int b = 12; </li></ul><ul><li>int c = a + b * (2 - a) / 4; </li></ul><ul><li...
Escape Sequences <ul><li>’  – Single quote </li></ul><ul><li>” – Double quote </li></ul><ul><li>– Backslash </li></ul><ul>...
Math class Methods Description Example Abs(x) Returns the absolute value of x Math.Abs(-45) is 45 Math.Abs(45) is 45 Round...
Math class Methods Description Example Pow(x,y) Returns x raised to the power y Math.Pow(4,2) is 16 Sqrt(x) Returns the sq...
Exercise <ul><li>Average </li></ul><ul><li>Min, Max </li></ul><ul><li>Separate the digits </li></ul>
Upcoming SlideShare
Loading in...5
×

C Sharp Jn (2)

565
-1

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
565
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

C Sharp Jn (2)

  1. 1. Software Development Training Program KaZIM HUSSAIn
  2. 2. Operators <ul><li>Operators can be used to combine or alter the program values. There are three types of operators: - </li></ul><ul><li>1. Unary Operators </li></ul><ul><li>2. Binary Operators </li></ul><ul><li>3. Ternary Operators </li></ul>
  3. 3. Unary Operators <ul><li>Unary Operators are that operators which require one operand to perform calculation. </li></ul><ul><li>-4; </li></ul><ul><li>5++; </li></ul>++ -- + ! - ~
  4. 4. Increment and Decrement Operator The ++ and – are increment and decrement operators. The increment operator increases its operand by one; the decrement operator decreases its operand by one. ++ --
  5. 5. Increment and Decrement Operator <ul><li>The expression </li></ul><ul><li>a = a + 1; </li></ul><ul><li>can written using increment operator as: </li></ul><ul><li>a++; </li></ul><ul><li>Similarly the statement </li></ul><ul><li>a = a – 1; </li></ul><ul><li>Is equal to following: </li></ul><ul><li>a--; </li></ul>
  6. 6. Increment and Decrement Operator <ul><li>The operator a++ first assign the value and then increment a by one. </li></ul><ul><li>These operators can be used as: </li></ul><ul><li>++a; </li></ul><ul><li>--a; </li></ul><ul><li>In this case the increment and decrement is done before assignment. </li></ul>
  7. 7. Examples Initial value of a Expression Final value of b Final value of a 5 b = a++ 5 6 5 b = ++a 6 6 5 b = a-- 5 4 5 b = --a 4 4
  8. 8. Bitwise Inversion Operator <ul><li>This operator performs bitwise inversion on integral types. This operator works by converting all the 1 bits in a binary to 0s and all the 0 to 1s. </li></ul>~
  9. 9. Bitwise Inversion Operator <ul><li>For example binary representation : </li></ul><ul><li>01001101 </li></ul><ul><li>Using the ~ operator convert into following </li></ul><ul><li>10110010 </li></ul><ul><li>You may notice that all the 0 bits are converted into 1s and all the 1 bits are converted into 0s. </li></ul>
  10. 10. Bitwise Inversion Operator <ul><li>For a positive value the result is always negative and increase the value by one. </li></ul><ul><li>For example: </li></ul><ul><li>~15 returns -16 </li></ul><ul><li>~1128 returns -1129 </li></ul><ul><li>~0 returns -1 </li></ul><ul><li>~8888888 returns -8888889 </li></ul>
  11. 11. Bitwise Inversion Operator <ul><li>For a negative value the result is always positive and decrease the value by one. </li></ul><ul><li>For example: </li></ul><ul><li>~-15 returns 14 </li></ul><ul><li>~-1128 returns 1127 </li></ul><ul><li>~-1 returns 0 </li></ul><ul><li>~-88888 returns 88887 </li></ul>
  12. 12. Boolean Complement Operator <ul><li>The ! Operator inverts the value of a boolean expression. So </li></ul><ul><li>!true results into false </li></ul><ul><li>!false results into true </li></ul>!
  13. 13. Binary Operators <ul><li>Binary Operators are that operators which require two operand to perform calculation. </li></ul><ul><li>4 / 2; </li></ul><ul><li>5 >= 7; </li></ul>Arithmetic Operators * / % + -
  14. 14. Binary Operators Comparison Operator Bitwise Operators Short Circuit Logical Operators & ^ | < <= > >= == != is as && ||
  15. 15. Binary Operators Assignment Operators = *= /= % = += -= & = ^= |=
  16. 16. Arithmetic Operators <ul><li>Basic arithmetic operators are addition(+), subtraction(-), multiplication(*), and division(/). All behave the same, as you would expect for all numeric types. Modulus(%) operator returns the remainder of a division operation. </li></ul>* / % + -
  17. 17. Comparison Operator <ul><li>These are also called relational operators. They determine the relationship that one operand has to the other. The outcome of these operators is always a boolean value. </li></ul>< <= > >= == != is as
  18. 18. Comparison Operator Operator Result == Equal to != Not equal to > Greater than < Less than >= Greater than or equal to <= Less than or equal to
  19. 19. Bitwise Operator <ul><li>The bitwise operators provides bitwise AND, XOR and OR operations respectively. These operators can be apply to both integer types and boolean types. These operators compare each bit of first operand with the corresponding bit of the second operand and give results according to following rules. </li></ul>& ^ |
  20. 20. Bitwise Operator (&) <ul><li>For AND operation 1 AND 1 results 1. any other combination produces 0. </li></ul>Op1 Op2 Op1 AND Op2 0 0 0 0 1 0 1 0 0 1 1 1
  21. 21. Bitwise Operator (|) <ul><li>For OR operations, 0 OR 0 produces 0. any other combination produces 1. </li></ul>Op1 Op2 Op1 OR Op2 0 0 0 0 1 1 1 0 1 1 1 1
  22. 22. Bitwise Operator (^) <ul><li>For XOR operations, 1 XOR 0 produces 1, as 0 XOR 1 does, any other combination produces 0. </li></ul>Op1 Op2 Op1 XOR Op2 0 0 0 0 1 1 1 0 1 1 1 0
  23. 23. Bitwise Operator <ul><li>The &,^ and | behave in the same way when applied to boolean. </li></ul>
  24. 24. Bitwise Operator (&) <ul><li>For AND operation true AND true results true. any other combination produces false. </li></ul>Op1 Op2 Op1 AND Op2 false false false false true false true false false true true true
  25. 25. Bitwise Operator (|) <ul><li>For OR operations, false OR false produces false. any other combination produces true. </li></ul>Op1 Op2 Op1 OR Op2 false false false false true true true false true true true true
  26. 26. Bitwise Operator (^) <ul><li>For XOR operations, true XOR false produces true, as false XOR true does, any other combination produces false. </li></ul>Op1 Op2 Op1 XOR Op2 false false false false true true true false true true true false
  27. 27. Short Circuit Logical Operators <ul><li>The short circuit logical operators && and || provide logical AND and OR operations on boolean types similar to the & and | operators. </li></ul><ul><li>However they have a valuable additional feature. </li></ul>&& ||
  28. 28. Short Circuit Logical Operators <ul><li>For an AND operation, if first operand is false, the result is false without checking the other operand. </li></ul><ul><li>For an OR operation, if first operand is true, the result is true, without checking the other operand. </li></ul>
  29. 29. Example <ul><li>int a = 5; </li></ul><ul><li>bool b = ( (a>8) && (a==5) ); </li></ul><ul><li>The first expression (a>8) returns false so the second expression (a==5) never executes and false is stored in b. </li></ul>
  30. 30. Example <ul><li>int a = 5; </li></ul><ul><li>bool b = ( (a>3) | | (a==2) ); </li></ul><ul><li>The first expression (a>3) returns true so the second expression (a==5) never executes and true is stored in b. </li></ul>
  31. 31. Assignment Operators = *= /= % = += -= & = ^=
  32. 32. Example <ul><li>int a = 6; </li></ul><ul><li>int b = 7; </li></ul><ul><li>a += b; result a=13 </li></ul><ul><li>a *= b; result a=42 </li></ul><ul><li>a /= b; result a=1 </li></ul><ul><li>a &= b; result a=6 </li></ul><ul><li>a ^= b; result a=1 </li></ul>
  33. 33. Ternary Operators <ul><li>Ternary Operators are that operators which require three operands to perform calculation. There is only one ternary operator in C#. </li></ul><ul><li>?: </li></ul><ul><li>(5>3) ? Value1 : Value2 </li></ul><ul><li>If (5>3) results true then Value1 is assign </li></ul><ul><li>otherwise Value2 is assign </li></ul>
  34. 34. Example <ul><li>int a = 5; </li></ul><ul><li>int b = a == 5 ? 6 : 1; </li></ul><ul><li>result b = 6; </li></ul><ul><li>bool c = a<5 ? false : true; </li></ul><ul><li>result c = ? //what </li></ul>
  35. 35. Operator Precedence <ul><li>Precedence </li></ul><ul><li>Associativity </li></ul>
  36. 36. Operator Precedence Category Operators Primary (x) x.y f(x) a[x] x++ x-- new typeof sizeof checked unchecked Unary = - ! ~ ++x --x (T)x Multiplicative * / % Additive + - Shift << >> Relational < > <= >= is as Equality == != Logical And & Logical XOR ^ Logical OR | Conditional AND && Conditional OR || Conditional ?: Assignment = *= /= %= += -= <<= >>= &= ^= |=
  37. 37. Examples <ul><li>int a = 9; </li></ul><ul><li>int b = 12; </li></ul><ul><li>int c = a & b + a | b; </li></ul><ul><li>result c = 13; </li></ul><ul><li>int a = 9; </li></ul><ul><li>int b = 12; </li></ul><ul><li>int c = a | b + a & b; </li></ul><ul><li>result c = 13; </li></ul>
  38. 38. Examples <ul><li>int a = 9; </li></ul><ul><li>int b = 12; </li></ul><ul><li>int c = a & b + ( a | b ) ; </li></ul><ul><li>result c = 9; </li></ul><ul><li>int a = 9; </li></ul><ul><li>int b = 12; </li></ul><ul><li>int c = a + b * 2 – a / 4 ; </li></ul><ul><li>result c = 31; </li></ul>
  39. 39. Examples <ul><li>int a = 9; </li></ul><ul><li>int b = 12; </li></ul><ul><li>int c = a + b * (2 - a) / 4; </li></ul><ul><li>result c = -12; </li></ul><ul><li>int a = 9; </li></ul><ul><li>int b = 12; </li></ul><ul><li>int c = a + b * ( (2 - a) / 4 ) ; </li></ul><ul><li>result c = -3; </li></ul>
  40. 40. Escape Sequences <ul><li>’ – Single quote </li></ul><ul><li>” – Double quote </li></ul><ul><li>– Backslash </li></ul><ul><li> – Backspace </li></ul><ul><li> – New Line </li></ul><ul><li> – Carriage Return </li></ul><ul><li> – Tab </li></ul>
  41. 41. Math class Methods Description Example Abs(x) Returns the absolute value of x Math.Abs(-45) is 45 Math.Abs(45) is 45 Round(x) Rounds a value to the nearest integer Math.Round(4.9) is 5 Math.Round(4.2) is 4 Math.Round(4.5) is 4 Ceiling(x) Returns the smallest integer greater than or equal to the x Math.Ceiling(5.4) is 6 Math.Ceiling(5.9) is 6 Floor(x) Returns the largest integer less then or equal to x Math.Floor(5.4) is 5 Math.Floor(5.9) is 5 Max(x,y) Returns the larger of two number Math.Max(5,9) is 9 Math.Max(5,-9) is 5 Min(x,y) Returns the smaller of two number Math.Min(5,9) is 5 Math.Min(5,-9) is -9
  42. 42. Math class Methods Description Example Pow(x,y) Returns x raised to the power y Math.Pow(4,2) is 16 Sqrt(x) Returns the square root of x Math.Sqrt(9) is 3 Math.Sqrt(5) is 2.23606797749979 Truncate(x) Returns the integral part of x Math.Truncate(38.4) is 38 Math.Truncate(38.485487) is 38
  43. 43. Exercise <ul><li>Average </li></ul><ul><li>Min, Max </li></ul><ul><li>Separate the digits </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×