I have recently noticed a curiosity (at least for me). I thought that the null-coalescing operator
would take the precedence over any mathematical operation but obviously i was wrong. I thought following two variables would have the same value at the end:
double? previousValue = null;
double? v1 = 1 + previousValue ?? 0;
double? v2 = 1 + (previousValue ?? 0);
But v2.Value
is (the desired) 1 whereas v1.Value
is still 0. Why?