O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required