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.

Image

FIGURE ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.