Thursday, June 30, 2011

C# Shortcuts (? Conditional Operator)


"?" operator is convenient. It allows you to pack a common "if then else" statement model in a single activity

Normally we use the following.


int x = 70;
int y = 95;
int min;

if (x < y)
  min = x;
else
  min = y;
But this can be written as...
int x = 70;
int y = 95;
int min = (x > y) ? x : y;

No comments:

Post a Comment