You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: standard/structs.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,6 +114,8 @@ struct_body
114
114
115
115
## 16.3 Struct members
116
116
117
+
### 16.3.1 General
118
+
117
119
The members of a struct consist of the members introduced by its *struct_member_declaration*s and the members inherited from the type `System.ValueType`.
118
120
119
121
```ANTLR
@@ -138,6 +140,46 @@ struct_member_declaration
138
140
139
141
Except for the differences noted in [§16.4](structs.md#164-class-and-struct-differences), the descriptions of class members provided in [§15.3](classes.md#153-class-members) through [§15.12](classes.md#1512-static-constructors) apply to struct members as well.
140
142
143
+
### 16.3.2 Readonly members
144
+
145
+
An instance member definition or accessor of an instance property, indexer, or event that includes the `readonly` modifier has the following restrictions:
146
+
147
+
- The `this` parameter is a `ref readonly` reference.
148
+
- The member shall not reassign the value of `this` or an instance field of the receiver.
149
+
- The member shall not reassign the value of an instance field-like event ([§15.8.2](classes.md#1582-field-like-events)) of the receiver.
150
+
- If a readonly member invokes a non-readonly member, the structure referred to by `this` must be copied to use a writable reference for the `this` argument.
151
+
152
+
> *Note:* Instance fields include the hidden backing field used for automatically implemented properties ([§15.7.4](classes.md#1574-automatically-implemented-properties)). *end note*
153
+
<!-- markdownlint-disable MD028 -->
154
+
155
+
<!-- markdownlint-enable MD028 -->
156
+
> *Example*: A readonly member can modify the state of an object referred to by an instance field, even though the readonly member can’t reassign that instance member. The following code demonstrates the reassigning and modifying an instance field:
0 commit comments