Pages

Wednesday 21 August 2013

One-liner if statements, how to convert this if-else-statement

Syntax :
return (expression) ? value1 : value2;
If value1 and value2 are actually true and false like in your example, you may as well just

return expression;
or
<result> = <condition> ? <true result> : <false result>;
Example :
string result = 5 > 10 ? "5 is greater than 10." : "5 is not greater than 10.";

No comments:

Post a Comment