Internal Representation

Not surprisingly, given the existing physical representation of value types and reference types, nullable value types are represented precisely as an encapsulation of this pattern (but one both the runtime and various languages such as C# know about).

Let’s start on the lowest level with the runtime. Given a value type, which intrinsically can’t accommodate for the null value, how do we create its nullable counterpart? The answer is Nullable<T>, a generic type where T is the type parameter that accepts a value type. Figure 4.38 dissects a nullable value in terms of a Boolean flag and an optional value of type T.



Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.