I am starting to work on some updates to the framework design guidelines related to new framework and language features added in .NET 2.0, 3.0, and 3.5. One of such additions are the nullable types (Nullable<T>).

Coincidentally, somebody asked me today whether they should use Nullable<bool>. Here is the question:

Q: Do the guidelines have anything to say about the use of nullable types in public API? Subject came up here in context of a proposal to return Nullable<bool> from a method to retrieve an attribute value (null means attribute not found, true means value retrieved, false means no value for existing attribute).

… and in the absence of formal guidelines, here is what I recommended:

A: I would say that the rule of thumb is that you should use Nullable<bool>, if it’s obvious what all three values mean. For example, it there is an optional column in a database of type Boolean, it’s clear that true means true, false means false, and null means the value is not there. In your example, you had to explain what the values mean, so I would not recommend using nullable types.