Where in memory are stored nullable types?

Posted by Ondrej Slinták on Stack Overflow See other posts from Stack Overflow or by Ondrej Slinták
Published on 2010-05-19T12:52:15Z Indexed on 2010/05/19 13:00 UTC
Read the original article Hit count: 266

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET