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 17 Classes 17.4 Fields 17.4.2 Readonly fields
Paragraph 11 When a field-declaration includes a readonly modifier, the fields introduced by the declaration are readonly fields. 2 Direct assignments to readonly fields can only occur as part of that declaration or in an instance constructor or static constructor in the same class. 3 (A readonly field can be assigned to multiple times in these contexts.) 4 Specifically, direct assignments to a readonly field are permitted only in the following contexts:
Paragraph 21 Attempting to assign to a readonly field or pass it as an out or ref parameter in any other context is a compile-time error.
- 5 In the variable-declarator that introduces the field (by including a variable-initializer in the declaration).
- 6 For an instance field, in the instance constructors of the class that contains the field declaration; for a static field, in the static constructor of the class that contains the field declaration. 7 These are also the only contexts in which it is valid to pass a readonly field as an out or ref parameter.
|Jagger Software Ltd|
|Company # 4070126|
|VAT # 762 5213 42|