23
Statements and Expressions [email protected] Programming in C#

3 statements and operators

Embed Size (px)

Citation preview

Page 1: 3   statements and operators

Statements and Expressions

[email protected]

Programming in C#

Page 2: 3   statements and operators

Types of Statements

Selection

| if, else, switch, case

Iteration

| for, foreach, while

Jump

| break, continue, default, goto, return, yield

Exception Handling

| throw, try-catch, try-finally, try-catch-finally

Checked and Unchecked

Fixed

| fixed, unsafe

Lock

Page 3: 3   statements and operators

Types of Operators

Page 4: 3   statements and operators

Types of Operators

Arithmetic

Relational

Logical

Conditional

Increment and Decrement

Assignment

Page 5: 3   statements and operators

Arithmetic Operators

are binary operators.

Page 6: 3   statements and operators

Relational Operators

Page 7: 3   statements and operators

Logical Operators Boolean Logical Operators

Bitwise Logical Operators

Page 8: 3   statements and operators

Bitwise Logical Operators Boolean Logical Operators

http://pastebin.com/BuXr5Zxq

AND

Page 9: 3   statements and operators

Conditional Operators

AND (&&) evaluates the second expression only if the first one return true. https://gist.github.com/2318365

OR (||) evaluates the second expression only if the first one return false. https://gist.github.com/2318398

Page 10: 3   statements and operators

Increment and Decrement Operators

Page 11: 3   statements and operators

Assignment Operators

Page 12: 3   statements and operators

Precedence and Associativity

Page 13: 3   statements and operators

Data Conversions

Page 14: 3   statements and operators

Typecasting

Page 15: 3   statements and operators

Implicit typecasting (Coercion) refers to an automatic conversion of data type

done when the destination data types belong to the same hierarchy and the destination data type must hold a larger range of values than the source data type

https://gist.github.com/2318445

Page 16: 3   statements and operators

Implicit typecasting (Coercion)

Page 17: 3   statements and operators

Explicit typecasting refers to changing a data type of higher precision into a data type of lower precision.

the destination data type hold a smaller range of values than the source data type

<tager data type> <variable name> = (target data type) <source data type>;

https://gist.github.com/2318452

Page 18: 3   statements and operators

Explicit typecasting using built-in method System.Convert class

Convert.ToChar(float)

ToString() method

https://gist.github.com/2318468

Page 19: 3   statements and operators

Boxing converting a value type to its reference type.

Page 20: 3   statements and operators

Unboxing converting a reference type to a value type

Page 21: 3   statements and operators

Boxing & Unboxing https://gist.github.com/2318516

Page 22: 3   statements and operators

Question?

What is the result of the following code snippets?

https://gist.github.com/2318553

Page 23: 3   statements and operators

Question?

What is the result of the following code snippets?

https://gist.github.com/2318553