by Emanuele
6/17/2008 3:32:00 PM
How many times did you write this code?
if (a == 1)
{
a = 1;
}
else
{
a = a - 1;
}
I say too much.
In Vb or in VB.net there is an operator called iif that do this in one row.
Is there IIF equivalent in C#?
Yes!!!
a==1 ? a=1 : a=a - 1;
You can use the operator ?: to obtain this goal.
The syntax is very simple:
<bool condition> ? <true value> : <false value>;
Enjoy!