… and the real name is ternary operator [thks pdh]…
I hope you know this way to write an if statement:
condition ? expression : expression
In .NET (hem and only c#) you can you this only as right operand such as:
a = (b > 50) ? 1 : 100;
you cannot use ?: to do something like this:
(b > 50) ? dothis() : dothat();
and hard to see, you cannot do this:
object a = (b > 50) ? "Hi There" : 999;
All expressions from right part have to return same type.
Keep in mind this is a great way to compact code, but somethimes it’s better think to keep code human readable.
Please call it by its name, “Ternary operator”.
You’re right, I’ve updated post. Thank you.
…years ago, I didn’t like too much studying, I preferred to write brute force code, and the result is that I’m a good coder but I have sparse holes in my knowledge…