The following code does not compile:
//int a = ...
int? b = (int?) (a != 0 ? a : null);
In order to compile, it needs to be changed to
int? b = (a != 0 ? a : (int?) null);
Since both b = null
and b = a
are legal, this doesn't make sense to me.
Why do we have to cast the null
into an int?
and why can't we simply provide an explicit type cast for the whole expression (which I know is possible in other cases)?