Prev | Current Page 229 | Next

Jon Skeet

"C# in Depth: What you need to master C# 2 and 3"

Like generics,
nullable types sometimes have some uses beyond what you might expect, and we??™ll
look at a few examples of these at the end of the chapter.
So, when is a value not a value? Let??™s find out.
This chapter covers
?–  Motivation for null values
?–  Framework and runtime support
?–  Language support in C# 2
?–  Patterns using nullable types
113 What do you do when you just don??™t have a value?
4.1 What do you do when you just don??™t have a value?
The C# and .NET designers don??™t add features just for kicks. There has to be a real, significant
problem to be fixed before they??™ll go as far as changing C# as a language or
.NET at the platform level. In this case, the problem is best summed up in one of the
most frequently asked questions in C# and .NET discussion groups:
I need to set my DateTime1 variable to null, but the compiler won??™t let me.
What should I do?
It??™s a question that comes up fairly naturally??”a simple example might be in an
e-commerce application where users are looking at their account history. If an order
has been placed but not delivered, there may be a purchase date but no dispatch
date??”so how would you represent that in a type that is meant to provide the
order details?
The answer to the question is usually in two parts: first, why you can??™t just use null
in the first place, and second, which options are available.


Pages:
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241