A boolean-expression is an expression that yields a result of type bool.
boolean-expression:
expression
The controlling conditional expression of an if-statement , while-statement , do-statement , or for-statement is a boolean-expression. The controlling conditional expression of the ?: operator 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 §11.4.2 provides an example of a type that implements operator true and operator false.
C# provides a variety of statements. Most of these statements will be familiar to developers who have programmed in C and C++.
statement:
labeled-statement
declaration-statement
embedded-statement
embedded-statement:
block
empty-statement
expression-statement
selection-statement
iteration-statement
jump-statement
try-statement
checked-statement
unchecked-statement
lock-statement
using-statement
yield-statement
The embedded-statement nonterminal is used for statements that appear within other statements. The use of embedded-statement rather than statement excludes the use of declaration statements and labeled statements in these contexts. The example
void F(bool b) {
if (b)
int i = 44;
}
results in a compile-time error because an if statement requires an embedded-statement rather than a statement for its if branch. If this code were permitted, then the variable i would be declared, but it could never be used. Note, however, that by placing i’s declaration in a block, the example is valid.