We??™ve got to be able to
store the values 0??“255 in that variable; otherwise it??™s useless for reading arbitrary
binary data. So, with the 256 ???normal??? values and one null value, we??™d have to cope
with a total of 257 values, and there??™s no way of squeezing that many values into a single
byte. Now, the designers could have decided that every value type would have an
extra flag bit somewhere determining whether a value was null or a ???real??? value, but
the memory usage implications are horrible, not to mention the fact that we??™d have to
check the flag every time we wanted to use the value. So in a nutshell, with value types
1 It??™s almost always DateTime rather than any other value type. I??™m not entirely sure why??”it??™s as if developers
inherently understand why a byte shouldn??™t be null, but feel that dates are more ???inherently nullable.???
114 CHAPTER 4 Saying nothing with nullable types
you often care about having the whole range of possible bit patterns available as real
values, whereas with reference types we??™re happy enough to lose one potential value
in order to gain the benefits of having a null value.
That??™s the usual situation??”now why would you want to be able to represent null
for a value type anyway? The most common immediate reason is simply because databases
typically support NULL as a value for every type (unless you specifically make the
field non-nullable), so you can have nullable character data, nullable integers, nullable
Booleans??”the whole works.
Pages:
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243