I'm maintaining some code and have found the following pattern a lot:
var isMale = (row["Gender"].ToString() == "M") ? true : false;
instead of this:
var isMale = (row["Gender"].ToString() == "M");
Is there any reason why anyone would do this? Does anyone think the former is more readable or clearer? Is there some sort of old C "gotcha" that this is a hold-over from?
if (y > z) x = y; else x = z; The following expression calls the function printf , which receives the value of the variable c , if c evaluates to a digit. Otherwise, printf receives the character constant 'x' .
The purpose of the conditional expression is to select one of two expressions depending on a third, boolean, expression. The format for the conditional expression is. <boolean-expression> ? < expression-1> : <expression-2>
A valid reason? No.
It's usually produced by people who don't really understand that a condition is also in itself an expression, producing a boolean result. In particular, people schooled on a language where this isn't the case, such as many variants of BASIC.
I guess if you get paid by the character that would be valid. Other than that I can't think of any reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With