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 12 Variables 12.3 Definite assignment
Paragraph 11 At a given location in the executable code of a function member, a variable is said to be definitely assigned if the compiler can prove, by static flow analysis, that the variable has been automatically initialized or has been the target of at least one assignment. 2 The rules of definite assignment are:
Paragraph 21 The definite assignment states of instance variables of a struct-type variable are tracked individually as well as collectively. 2 In additional to the rules above, the following rules apply to struct-type variables and their instance variables:
- 3 An initially assigned variable (§12.3.1) is always considered definitely assigned.
- 4 An initially unassigned variable (§12.3.2) is considered definitely assigned at a given location if all possible execution paths leading to that location contain at least one of the following:
- 5 A simple assignment (§14.13.1) in which the variable is the left operand.
- 6 An invocation expression (§14.5.5) or object creation expression (§18.104.22.168) that passes the variable as an output parameter.
- 7 For a local variable, a local variable declaration (§15.5) that includes a variable initializer.
Paragraph 31 Definite assignment is a requirement in the following contexts:
- 3 An instance variable is considered definitely assigned if its containing struct-type variable is considered definitely assigned.
- 4 A struct-type variable is considered definitely assigned if each of its instance variables is considered definitely assigned.
[Note: This ensures that the function member being invoked can consider the reference parameter initially assigned. end note]
- 2 A variable must be definitely assigned at each location where its value is obtained. [Note: This ensures that undefined values never occur. end note] 3 The occurrence of a variable in an expression is considered to obtain the value of the variable, except when
- 4 the variable is the left operand of a simple assignment,
- 5 the variable is passed as an output parameter, or
- 6 the variable is a struct-type variable and occurs as the left operand of a member access.
- 7 A variable must be definitely assigned at each location where it is passed as a reference parameter.
- 8 All output parameters of a function member must be definitely assigned at each location where the function member returns (through a return statement or through execution reaching the end of the function member body). [Note: This ensures that function members do not return undefined values in output parameters, thus enabling the compiler to consider a function member invocation that takes a variable as an output parameter equivalent to an assignment to the variable. end note]
- 9 The this variable of a struct-type instance constructor must be definitely assigned at each location where that instance constructor returns.
|Jagger Software Ltd|
|Company # 4070126|
|VAT # 762 5213 42|