Possible Duplicate:
Is the ternary operator evil?
Does using shorthand if else statments hurt readability?
Compare:
string name = street != null ? street.Owner : "Not known";
With:
string name;
if(street != null)
{
name = street.Owner;
}
else
{
name = "Not known";
}
I have become familiar enough with the shorthand that its just as readable for short statements as the long version. Is that true for most developers or should I favor the more verbose version
string name = street?.Owner ?? "Not known";
Not exactly the same though, as it will overwrite non-nullstreet
ifstreet.Owner == null
. – Gábor Imre Feb 14 '20 at 15:22