Prev | Current Page 228 | Next

Jon Skeet

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

Comments and variable names
can often become inaccurate over time, as they can be left alone when code is
changed??”but the type information is ???correct??? by definition.
Generics aren??™t capable of doing everything we might sometimes like them to do,
and we??™ve studied some of their limitations in the chapter, but if you truly embrace
C# 2 and the generic types within the .NET 2.0 Framework, you??™ll come across good
uses for them incredibly frequently in your code.
This topic will come up time and time again in future chapters, as other new features
build on this key one. Indeed, the subject of our next chapter would be very
different without generics??”we??™re going to look at nullable types, as implemented
by Nullable.
112
Saying nothing
with 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??”before we see how C# 2
makes working with nullable types a bit simpler and more compact.


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