This documentation is archived and is not being maintained.

7.16 Boolean expressions

Visual Studio .NET 2003

A boolean-expression is an expression that yields a result of type bool.

boolean-expression:
expression

The controlling conditional expression of an if-statement (Section 8.7.1), while-statement (Section 8.8.1), do-statement (Section 8.8.2), or for-statement (Section 8.8.3) is a boolean-expression. The controlling conditional expression of the ?: operator (Section 7.12) follows the same rules as a boolean-expression, but for reasons of operator precedence is classified as a conditional-or-expression.

A boolean-expression is required to be of a type that can be implicitly converted to bool or of a type that implements operator true. If neither requirement is satisfied, a compile-time error occurs.

When a Boolean expression is of a type that cannot be implicitly converted to bool but does implement operator true, then following evaluation of the expression, the operator true implementation provided by that type is invoked to produce a bool value.

The DBBool struct type in Section 11.4.2 provides an example of a type that implements operator true and operator false.

Show: