Where in memory are stored nullable types?
- by Ondrej Slinták
This is maybe a follow up to question about nullable types.
Where exactly are nullable value types (int?...) stored in memory? First I thought it's clear enough, as Nullable<T> is struct and those are value types. Then I found Jon Skeet's article "Memory in .NET", which says:
Note that a value type variable can
never have a value of null - it
wouldn't make any sense, as null is a
reference type concept, meaning "the
value of this reference type variable
isn't a reference to any object at
all".
I am little bit confused after reading this statement. So let's say I have int? a = null;. As int is normally a value type, is it stored somehow inside struct Nullable<T> in stack (I used "normally" because I don't know what happens with value type when it becomes nullable)? Or anything else happens here - perhaps in heap?