Prev | Current Page 250 | Next

Jon Skeet

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

The date of Alan Turing??™s death D is created
by calling the normal DateTime constructor and then passing the result into the
Nullable constructor, which takes a parameter.
I mention looking at the IL because that can be a useful way of finding out what
your code is actually doing, particularly if something compiles when you don??™t expect
it to. You can use the ildasm tool that comes with the .NET SDK, or for a rather better
user interface you can use Reflector,3 which has many other features (most notably
decompilation to high-level languages such as C# as well as disassembly to IL).
We??™ve seen how C# provides shorthand syntax for the concept of a null value, making
the code more expressive once nullable types are understood in the first place. However,
one part of listing 4.4 took a bit more work than we might have hoped??”the subtraction
at C. Why did we have to unwrap the value? Why could we not just return death-birth
directly? What would we want that expression to mean in the case (excluded in our code
by our earlier test for null, of course) where death had been null? These questions??”
and more??”are answered in our next section.
3 Available free of charge from http://www.aisto.com/roeder/dotnet/
Wraps DateTime
as a nullable
D
Specifies a null
date of death
E
124 CHAPTER 4 Saying nothing with nullable types
4.3.3 Nullable conversions and operators
We??™ve seen that we can compare instances of nullable types with null, but there are
other comparisons that can be made and other operators that can be used in some
cases.


Pages:
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262