Conditional / Ternary Operator

Conditional Operator / Ternary Operator :
  • condition ? true_expression : false_expression;
  • bool x = condition ? true : false;
eg :
string result = (percentage >= 36) ? "pass" : "fail" ;

--------------------------------------------------------
NullCoalesce (??)
  • int totalMarks = marks ?? 0 ;
The ?? operator is called the null-coalescing operator. It returns the left-hand operand if the operand is not null; otherwise it returns the right hand operand.eg: 
int? x = null; 
int y = x ?? -1;
int? is a shorthand for Nullable, which itself is shorthand of Nullable. 
eg Nullable a = null;
A nullable type can represent the correct range of values for its underlying 
value type, plus a additional null value.


--------------------------------------------------------

Comments

Popular posts from this blog

Bounding Box in PIL (Python Image Library)

Dictionary vs KeyValuePair vs Struct - C#

Rendering order and Z-sorting