Nullable Boolean Logic

Logic involving nullable Boolean values is three valued and mirrored after the SQL behavior. The idea is pretty much based on the short-circuiting observation: For AND, if any of the operands are false, the whole result ought to be false (similar for OR, but with the true value). In other words, we don’t care if the other operand is null in such a case; the result is well defined. Figure 5.23 summarizes nullable Boolean logic.

Figure 5.23. Truth tables for nullable Boolean logic.

image

Personally, I try to avoid nullable Booleans in decision logic wherever possible. Even though everything seems “logical,” basic laws of logic become ...

Get C# 4.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.