Are function arguments always evaluated in a C# null-conditional function call?
i.e. in the following code:
obj?.foo(bar());
Is bar evaluated if obj is null?
Are function arguments always evaluated in a C# null-conditional function call?
i.e. in the following code:
obj?.foo(bar());
Is bar evaluated if obj is null?
On
Running test code indicates that in the Microsoft compiler at least the arguments are not evaluated, however the C# specification doesn't seem to specify this as required behaviour.
The spec specifies that
In your case,
Pisobj.Aisfoo(bar()). If we expand both cases:By the semantics of the ternary operator, when
objis null, the third operand,obj.foo(bar())will not be evaluated.