How is nullable type implemented by .NET ?
Nullable<int> x = 5;
int? x = 5;
How is nullable type implemented by .NET ?
Nullable<int> x = 5;
int? x = 5;
Yes, is the same in .net
int? variable = 5;
So a Nullable<t>
has two main properties: value
and hasValue
Now if you have a value type (such as an int) - it can never have a null value, in the case of an int it would have an initial value of 0.
Since however value
is a property, you can keep track separately of whether it's set to null or not, and if it's null yet you try to use the getter method of the value
property, it can throw an exception.