int? x = null;
x = x + 1; // Works, but x remains null
I would expect the compiler to attempt to cast x as an int, but apparently it does not.
Edit by 280Z28: Changed NullReferenceException
to InvalidOperationException
, which is what Nullable<T>.Value
throws when HasValue
is false.