I was wondering – when would I want to use the .Value member on a nullable type instead of just calling the variable itself?
e.g..
bool? b = true;
why would i use b.Value to get the value instead of just using b? What advantage or function does the .Value call add?
The value property is read only and will return the actual value type. The value property can never be null.
If you expect to have a nullable return a value then check .HasValue and then reference Value. For instance, if you want to assign the value of a Nullable to an ordinary bool then you have to reference it’s value:
However, the following won’t compile: