Why do we need explicit cast in second statement?
bool? a = null;
bool b = false;
bool c = true;
1.)
if(b || c)
a = b;
else
a = null;
2.) a = (b || c)?(Nullable<bool>)b:null;
The conditional operator is an expression, thus it needs a return type - also both cases have to have the same return type. In your case, there is no way of determining the return type automatically, thus you need to cast.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With