So I have been intrigued by the ?? operator, but have still been unable to use it. I usually think about it when I am doing something like:
var x = (someObje
Just as an FYI, the ternary operator generates a different sequence of IL from the null coalescing operator. The first looks something like such:
// string s = null;
// string y = s != null ? s : "Default";
ldloc.0
brtrue.s notnull1
ldstr "Default"
br.s isnull1
notnull1: ldloc.0
isnull1: stloc.1
And the latter looks like such:
// y = s ?? "Default";
ldloc.0
dup
brtrue.s notnull2
pop
ldstr "Default"
notnull2: stloc.1
Based on this, I'd say the null coalescing operator is optimized for its purpose and is not just syntactic sugar.