Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specification


14 Expressions
14.11 Conditional logical operators
14.11.2 User-defined conditional logical operators
Paragraph 11 When the operands of && or || are of types that declare an applicable user-defined operator & or operator |, both of the following must be true, where T is the type in which the selected operator is declared: - 2 The return type and the type of each parameter of the selected operator must be T. 3 In other words, the operator must compute the logical AND or the logical OR of two operands of type T, and must return a result of type T.
- 4 T must contain declarations of operator true and operator false.
Paragraph 21 A compile-time error occurs if either of these requirements is not satisfied. 2 Otherwise, the && or || operation is evaluated by combining the user-defined operator true or operator false with the selected user-defined operator: - 3 The operation x && y is evaluated as T.false(x) ? x : T.&(x, y), where T.false(x) is an invocation of the operator false declared in T, and T.&(x, y) is an invocation of the selected operator &. 4 In other words, x is first evaluated and operator false is invoked on the result to determine if x is definitely false. 5 Then, if x is definitely false, the result of the operation is the value previously computed for x. 6 Otherwise, y is evaluated, and the selected operator & is invoked on the value previously computed for x and the value computed for y to produce the result of the operation.
- 7 The operation x || y is evaluated as T.true(x) ? x : T.|(x, y), where T.true(x) is an invocation of the operator true declared in T, and T.|(x, y) is an invocation of the selected operator |. 8 In other words, x is first evaluated and operator true is invoked on the result to determine if x is definitely true. 9 Then, if x is definitely true, the result of the operation is the value previously computed for x. 10 Otherwise, y is evaluated, and the selected operator | is invoked on the value previously computed for x and the value computed for y to produce the result of the operation.
Paragraph 31 In either of these operations, the expression given by x is only evaluated once, and the expression given by y is either not evaluated or evaluated exactly once.
Paragraph 41 For an example of a type that implements operator true and operator false, see §18.4.2. |
Jagger Software Ltd |
Company # 4070126 |
VAT # 762 5213 42 |

