Is there any difference between type? and Nullable<type>?
If you look at the IL using Ildasm, you'll find that they both compile down to Nullable<bool>
.
There is no difference between bool? b = null
and Nullable<bool> b = null
. The ?
is just C# compiler syntax sugar.
To access the value of the bool? you need to do the following:
bool? myValue = true;
bool hasValue = false;
if (myValue.HasValue && myValue.Value)
{
hasValue = true;
}
Note you can't just do:
if (myValue)
{
hasValue = true;
}