Does the method on the left side of the ?? operator in C# get called twice? Once for the evaluation and once for the assignment?
In the following line:
int i = GetNullableInt() ?? default(int); I would assume that the GetNullableInt() method would need to be called first, so the result could be evaluated, before making the assignment. If this does NOT happen then the variable "i" would need to be assigned and then evaluated which seems dangerous for the item receiving the assignment in that, during an object assignment, it could theoretically be prematurely assigned a null value during the first stage only to have it replaced by the result of the method on the right.
i, checks the if the value ofiisnull, and if yes - assigns the right part. That's how I would do it.....i. While the runtime has a lot of options, generally this, (along with actually quite a lot of operations) results in an implicit unnamed temporary variable. After all, consider what would happen if the expression itself usediwithin itican never be null. The null-coalescing expression is fully evaluated, and the result assigned toi.