3 ms·
The use of the ternary operator for such things as: String a = (b == null) ? "" : b; is okay with me, at least, when I'm working in languages other than C#, wh
by moron4hire 16y ago
The use of the ternary operator for such things as:
String a = (b == null) ? "" : b;
is okay with me, at least, when I'm working in languages other than C#, where it's just:
string a = b ?? "";
I also use it within other operations, like:
var output = string.Format("Something {0} something {1}",
string1.Length > 0 ? string1 : "N/A",
string2.Length > 0 ? string2 : "whoops");
My general rule of thumb is, if breaking the ternary operation into multiple lines will make it more readable, then you're going too far with the ternary operator.