Monday, June 15, 2009

Question Mark Operator C#

The question mark operator is a 'ternary' operator that allows a conditional statement to be written in one line.

if a function returns a boolean :

return someVar == anotherVar ? true : false;

is equivalent to

if(someVar == anotherVar)
{
return true;
}
else
{
return false;
]

No comments:

Post a Comment