The true operator returns the bool value true to indicate that an operand is definitely true. The false operator returns the bool value true to indicate that an operand is definitely false. The true and false operators are not guaranteed to complement each other. That is, both the true and false operator might return the bool value false for the same operand. If a type defines one of the two operators, it must also define another operator.
If a type with the defined true and false operators overloads the logical OR operator | or the logical AND operator & in a certain way, the conditional logical OR operator || or conditional logical AND operator &&, respectively, can be evaluated for the operands of that type. For more information, see the User-defined conditional logical operators section of the C# language specification.
A type with the defined true operator can be the type of a result of a controlling conditional expression in the if, do, while, and for statements and in the conditional operator ?:. For more information, see the Boolean expressions section of the C# language specification.
Use the bool? type, if you need to support the three-valued logic, for example, when you work with databases that support a three-valued Boolean type. C# provides the & and | operators that support the three-valued logic with the bool? operands. For more information, see the Nullable Boolean logical operators section of the Boolean logical operators article.
The following example presents the type that defines both true and false operators. Moreover, it overloads the logical AND operator & in such a way that the operator && also can be evaluated for the operands of that type.