How to check if an object is nullable?

There are two types of nullable – Nullable<T> and reference-type. Jon has corrected me that it is hard to get type if boxed, but you can with generics: – so how about below. This is actually testing type T, but using the obj parameter purely for generic type inference (to make it easy to call) … Read more

Nullable types and the ternary operator: why is `? 10 : null` forbidden? [duplicate]

The compiler first tries to evaluate the right-hand expression: GetBoolValue() ? 10 : null The 10 is an int literal (not int?) and null is, well, null. There’s no implicit conversion between those two hence the error message. If you change the right-hand expression to one of the following then it compiles because there is … Read more