Chapter 4. Saying nothing with nullable types
This chapter covers
Motivation for null values
Framework and runtime support
Language support in C# 2
Patterns using nullable types
Nullity is a concept that has provoked a certain amount of debate over the years. Is a null reference a value, or the absence of a value? Is “nothing” a “something”? In this chapter, I’ll try to stay more practical than philosophical. First we’ll look at why there’s a problem in the first place—why you can’t set a value type variable to null
in C# 1 and what the traditional alternatives have been. After that I’ll introduce you to our knight in shining armor—System.Nullable<T>
—before we see how C# 2 makes working with nullable types a bit simpler and more compact. Like generics, ...
Get C# in Depth 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.