object bread(food foo)
{
return foo.ingredient ?? "cheese";
}
If foo exits, but ingredient is null
, I get "cheese"
.
My question, including an assumption:
If foo itself is null
will "chesse"
be returned or will it throw an ArgutmentNullException
?
My GUESS is that the NullCoalescingOperator is implemented more or less like this:
object nco(object lhs, object rhs)
{
if(lhs != null)
return lhs;
else
return rhs;
}
Therefore passing foo.ingredient
already causes the exception(since you cannot check a field in an object that you don't have) and thus it is thrown.
Would make sense.
Is this idea correct / how is the nco implemented and why?