ECMA-334 C# Language Specification17.4.2: Readonly fields |
When a field-declaration
includes a readonly modifier, the fields introduced by the declaration are readonly fields. 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. (A readonly field can be assigned to multiple times in these contexts.) Specifically, direct assignments to a readonly field are permitted only in the following contexts:
variable-declarator
that introduces the field (by including a variable-initializer
in the declaration). 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.
In This Section: