Saturday, March 29, 2008

Ternary Operator ( ? : )

The Ternary Operator is another form of an if statement. (Ternary means "consisting of 3 things".)
The format is: condition ? true part : false part

For example, this:
string name = paramName != null ? paramName : "No name provided"; 
Is basically the same as this:
string name; 
if (paramName != null) 
{
     name = paramName; 
} 
else 
{
     name = "No name provided"; 
}
More info: MSDN: Ternary Operator