ECMA-334: 12.3.3.26 ?: expressions
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
12.3.3.26 ?: expressions
For an expression expr of the form expr-cond ? expr-true : expr-false:
- The definite assignment state of v before expr-cond is the same as the state of v before expr.
- The definite assignment state of v before expr-true is definitely assigned if and only if the state of v after expr-cond is definitely assigned or "definitely assigned after true expression".
- The definite assignment state of v before expr-false is definitely assigned if and only if the state of v after expr-cond is definitely assigned or "definitely assigned after false expression".
- The definite assignment state of v after expr is determined by:
- If expr-cond is a constant expression (§14.16) with value
truethen the state of v after expr is the same as the state of v after expr-true.
- If expr-cond is a constant expression (§14.16) with value
- Otherwise, if expr-cond is a constant expression (§14.16) with value
falsethen the state of v after expr is the same as the state of v after expr-false.
- Otherwise, if expr-cond is a constant expression (§14.16) with value
- Otherwise, if the state of v after expr-true is definitely assigned and the state of v after expr-false is definitely assigned, then the state of v after expr is definitely assigned.
- Otherwise, the state of v after expr is not definitely assigned.