I know that it is possible to have Nullable value types that wraps the value type and gives ability to store null.
But is there a technical reason do not allow the value type to be null or the reason is only conceptual?
I know that it is possible to have Nullable value types that wraps the
Share
A reference type is storeed as a reference (like a pointer) to an object instance.
nullmeans a reference that isn’t pointing to an instance of an object.Value types are stored as the values themselves, without any references.
Therefore, it doesn’t make sense to have a
nullvalue type—the value type by definition contains a value.Nullable<T>is a value type with aHasValueflag that can befalseto indicate that there is no value. It still has a value (whenHasValueisfalse,Valueisdefault(T)), but theHasValueflag tells you to ignore the value.It has nothing to do with
null, except that the CLR automatically unboxesnullboxed values to aNullable<T>withHasValueset tofalse.