A Type Background

From a type perspective, you can draw the parallel to array types and generic types as type constructors. Given a type, another type can be constructed thanks to out-of-the-box runtime and language facilities. For nullable value types, that’s the case, too, but with some restrictions. As the name implies, they’re only supported over value types, but it’s also impossible to “nest” them, as in int?? or Nullable<Nullable<int>>.

The top part of Figure 4.40 shows the principle of a type constructor. Given any type T, as indicated by the dotted-lined box, a more complex type can be created. In this example, it’s a Nullable<T> type that provides a box around the original type with the HasValue and Value properties on it. At the bottom, ...

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.