For the second case to work with the ternary operator, you can use the following:
int result = input != null ? input.Value : 10;
The Value property of type Nullable<T> returns the value T (in this case, int ).
Another option is to use Nullable<T>.HasValue :
int result = input.HasValue ? input.Value : 10;
The myNullableInt != null construct is just the syntax sugar for the above HasValue call.
source share