Jon Jagger
jon@jaggersoft.com
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 Specificationpreviousnextprevious at this levelnext at this level 14 Expressionsprevious at this levelnext at this level 14.12 Conditional operator Paragraph 11 The ?: operator is called the conditional operator. 2 It is at times also called the ternary operator. conditional-expression : conditional-or-expression conditional-or-expression ? expression : expression Paragraph 21 A conditional expression of the form b ? x : y first evaluates the condition b. 2 Then, if b is true, x is evaluated and becomes the result of the operation. 3 Otherwise, y is evaluated and becomes the result of the operation. 4 A conditional expression never evaluates both x and y. Paragraph 31 The conditional operator is right-associative, meaning that operations are grouped from right to left. 2 For example, an expression of the form a ? b : c ? d : e is evaluated as a ? b : (c ? d : e). Paragraph 41 The first operand of the ?: operator must be an expression of a type that can be implicitly converted to bool, or an expression of a type that implements operator true. 2 If neither of these requirements is satisfied, a compile-time error occurs. Paragraph 51 The second and third operands of the ?: operator control the type of the conditional expression. 2 Let X and Y be the types of the second and third operands. 3 Then, Paragraph 61 The run-time processing of a conditional expression of the form b ? x : y consists of the following steps:
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS