This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!
10.4.2 Readonly fields
When a field-declaration includes a readonly
modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class. Specifically, assignments to a readonly
field are permitted only in the following contexts:
- In the variable-declarator that introduces the field (by including a variable-initializer in the declaration).
- For an instance field, in the instance constructors of the class that contains the field declaration, or for a static field, in the static constructor of the class the contains the field declaration. These are also the only contexts in which it is valid to pass a
readonly
field as an out
or ref
parameter.
Attempting to assign to a readonly
field or pass it as an out
or ref
parameter in any other context is an error.