Prev | Current Page 256 | Next

Jon Skeet

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

Value-birth in listing 4.4 instead of just death-birth. Applying the previous
rules, we could have used the latter expression, but the result would have been a
TimeSpan? instead of a TimeSpan. This would have left us with the options of casting the
result to TimeSpan, using its Value property, or changing the Age property to return a
TimeSpan???”which just pushes the issue onto the caller. It??™s still a bit ugly, but we??™ll see
a nicer implementation of the Age property in section 4.3.5.
In the list of restrictions regarding operator lifting, I mentioned that bool? works
slightly differently than the other types. Our next section explains this and pulls back
the lens to see the bigger picture of why all these operators work the way they do.
4.3.4 Nullable logic
I vividly remember my early electronics lessons at school. They always seemed to
revolve around either working out the voltage across different parts of a circuit using
the V=IR formula, or applying truth tables??”the reference charts for explaining the difference
between NAND gates and NOR gates and so on. The idea is simple??”a truth
table maps out every possible combination of inputs into whatever piece of logic
you??™re interested in and tells you the output.
The truth tables we drew for simple, two-input logic gates always had four rows??”
each of the two inputs had two possible values, which means there were four possible
combinations.


Pages:
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268