Still think Ternary operators are evil?
OK, I’ve seen a lot of the VB guys complaining that using the ternary operator (which VB.NET just got as of 3.5) makes the code unclear. To which I’ve said said, and continue to say, “Yes of course, if used incorrectly.”
But, this post, over at ASP.NET without ASP.NET shows a pratical use of the ternary operator and shows that it can be a lot more clear than multiple if/else if statements.
Now, we all know that a case statement would be preferred to multiple if/else if statements WHEN THAT IS POSSIBLE. But, sometimes your if/else if is either not comparing against the same value, or is comparing multiple values. In both cases, a switch statement will not work, or be as clear as this example of the ternary operator.
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!



















































