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.

Image

FIGURE 5.23 Truth tables for nullable Boolean logic.

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

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.