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/classes.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3351,7 +3351,11 @@ The *member_name* ([§15.6.1](classes.md#1561-general)) specifies the name of th
3351
3351
3352
3352
The *type* of a property shall be at least as accessible as the property itself ([§7.5.5](basic-concepts.md#755-accessibility-constraints)).
3353
3353
3354
+
<<<<<<< HEAD
3354
3355
A *property_body* may either consist of a statement body or an expression body. In a statement body, *accessor_declarations*, which shall be enclosed in “`{`” and “`}`” tokens, declare the accessors ([§15.7.3](classes.md#1573-accessors)) of the property. The accessors specify the executable statements associated with reading and writing the property.
3356
+
=======
3357
+
A *property_body* may either consist of a ***statement body*** or an expression body. In a statement body, *accessor_declarations*, which shall be enclosed in “`{`” and “`}`” tokens, declare the accessors ([§15.7.3](classes.md#1573-accessors)) of the property. The accessors specify the executable statements associated with reading and writing the property.
3358
+
>>>>>>> f62f619 (fix formatting, add xref links)
3355
3359
3356
3360
In a *property_body* an expression body consisting of `=>` followed by an *expression*`E` and a semicolon is exactly equivalent to the statement body `{ get { return E; } }`, and can therefore only be used to specify read-only properties where the result of the get accessor is given by a single expression.
3357
3361
@@ -3385,8 +3389,10 @@ The *accessor_declarations* of a property specify the executable statements asso
The *accessor_declarations* consist of either a *get_accessor_declaration*, optionally with a *set_accessor_declaration* or an *init_accessor_declaration*, or a *set_accessor_declaration* or *init_accessor_declaration optionally with a *get_accessor_declaration*. Each accessor declaration consists of optional attributes, an optional *accessor_modifier*, the token `get`, `init`, or `set`, followed by an *accessor_body*.
3438
+
The *accessor_declarations* consist of either a *get_accessor_declaration*, optionally with a *set_accessor_declaration* or an *init_accessor_declaration*, or a *set_accessor_declaration* or *init_accessor_declaration* optionally with a *get_accessor_declaration*. Each accessor declaration consists of optional *attributes*, an optional *accessor_modifier*, the token `get`, `init`, or `set`, followed by an *accessor_body*.
3433
3439
3434
3440
For a ref-valued property the *ref_get_accessor_declaration* consists optional attributes, an optional *accessor_modifier*, the token `get`, followed by an *ref_accessor_body*.
3435
3441
@@ -3486,17 +3492,17 @@ The body of a get accessor for a ref-valued property shall conform to the rules
An init accessor corresponds to a method with a single value parameter of the property type and a `void` return type. The implicit parameter of an init accessor is always named `value`. Only during the construction phase of an object, and if an init accessor exists, when a property is referenced as the target of an assignment ([§12.21](expressions.md#1221-assignment-operators)), or as the operand of `++` or `–-` ([§12.8.15](expressions.md#12815-postfix-increment-and-decrement-operators), [§12.9.6](expressions.md#1296-prefix-increment-and-decrement-operators)), the init accessor is invoked with an argument that provides the new value ([§12.21.2](expressions.md#12212-simple-assignment)). The body of an init accessor shall conform to the rules for `void` methods described in [§15.6.11](classes.md#15611-method-body). In particular, return statements in the init accessor body are not permitted to specify an expression. Since an init accessor implicitly has a parameter named `value`, it is a compile-time error for a local variable or constant declaration in an init accessor to have that name.
3495
+
An init accessor corresponds to a method with a single value parameter of the property type and a `void` return type. The implicit parameter of an init accessor is always named `value`. Only during the construction phase of an object (§init-accessors), and if an init accessor exists, when a property is referenced as the target of an assignment ([§12.21](expressions.md#1221-assignment-operators)), or as the operand of `++` or `–-` ([§12.8.15](expressions.md#12815-postfix-increment-and-decrement-operators), [§12.9.6](expressions.md#1296-prefix-increment-and-decrement-operators)), the init accessor is invoked with an argument that provides the new value ([§12.21.2](expressions.md#12212-simple-assignment)). The body of an init accessor shall conform to the rules for `void` methods described in [§15.6.11](classes.md#15611-method-body). In particular, return statements in the init accessor body are not permitted to specify an expression. Since an init accessor implicitly has a parameter named `value`, it is a compile-time error for a local variable or constant declaration in an init accessor to have that name.
Whenapropertyisspecifiedasanautomaticallyimplementedproperty, ahiddenbackingfieldisautomaticallyavailablefortheproperty, andtheaccessorsareimplementedtoreadfromandwritetothatbackingfield. Thehiddenbackingfieldisinaccessible, itcanbereadandwrittenonlythroughtheautomaticallyimplementedpropertyaccessors, evenwithinthecontainingtype. Iftheauto-propertyhasnosetorinitaccessor, thebackingfieldisconsidered `readonly` ([§15.5.3](classes.md#1553-readonly-fields)). Justlikea `readonly` field, aread-onlyauto-propertymayalsobeassignedtointhebodyofaconstructoroftheenclosing class. Such an assignment assigns directly to the read-only backing field of the property. If the auto-property has an init accessor, the backing field may be assigned to during the construction phase of an object.
3971
+
Whenapropertyisspecifiedasanautomaticallyimplementedproperty, ahiddenbackingfieldisautomaticallyavailablefortheproperty, andtheaccessorsareimplementedtoreadfromandwritetothatbackingfield. Thehiddenbackingfieldisinaccessible, itcanbereadandwrittenonlythroughtheautomaticallyimplementedpropertyaccessors, evenwithinthecontainingtype. Iftheauto-propertyhasnosetorinitaccessor, thebackingfieldisconsidered `readonly` ([§15.5.3](classes.md#1553-readonly-fields)). Justlikea `readonly` field, aread-onlyauto-propertymayalsobeassignedtointhebodyofaconstructoroftheenclosing class. Such an assignment assigns directly to the read-only backing field of the property. If the auto-property has an init accessor, the backing field may be assigned to during the construction phase of an object (§init-accessors).
3966
3972
3967
3973
An auto-property may optionally have a *property_initializer*, which is applied directly to the backing field as a *variable_initializer* ([§17.7](arrays.md#177-array-initializers)).
0 commit comments