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
+26-4Lines changed: 26 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3087,6 +3087,7 @@ accessor_modifier
3087
3087
3088
3088
accessor_body
3089
3089
: block
3090
+
| '=>' expression ';'
3090
3091
| ';'
3091
3092
;
3092
3093
```
@@ -3104,7 +3105,10 @@ The use of *accessor_modifier*s is governed by the following restrictions:
3104
3105
- If the property or indexer has a declared accessibility of `internal` or `protected`, the *accessor_modifier* shall be `private`.
3105
3106
- If the property or indexer has a declared accessibility of `private`, no *accessor_modifier* may be used.
3106
3107
3107
-
For `abstract` and `extern` properties, the *accessor_body* for each accessor specified is simply a semicolon. A non-abstract, non-extern property may also have the *accessor_body* for all accessors specified be a semicolon, in which case it is an ***automatically implemented property*** ([§14.7.4](classes.md#1474-automatically-implemented-properties)). An automatically implemented property shall have at least a get accessor. For the accessors of any other non-abstract, non-extern property, the *accessor_body* is a *block* that specifies the statements to be executed when the corresponding accessor is invoked.
3108
+
For `abstract` and `extern` properties, the *accessor_body* for each accessor specified is simply a semicolon. A non-abstract, non-extern property may also have the *accessor_body* for all accessors specified be a semicolon, in which case it is an ***automatically implemented property*** ([§14.7.4](classes.md#1474-automatically-implemented-properties)). An automatically implemented property shall have at least a get accessor. For the accessors of any other non-abstract, non-extern property, the *accessor_body* is either
3109
+
3110
+
- a *block* that specifies the statements to be executed when the corresponding accessor is invoked; or
3111
+
- an expression body, which consists of `=>` followed by an *expression* and a semicolon, and denotes a single expression to be executed when the corresponding accessor is invoked.
3108
3112
3109
3113
A get accessor corresponds to a parameterless method with a return value of the property type. Except as the target of an assignment, when a property is referenced in an expression, the get accessor of the property is invoked to compute the value of the property ([§11.2.2](expressions.md#1122-values-of-expressions)). The body of a get accessor shall conform to the rules for value-returning methods described in [§14.6.11](classes.md#14611-method-body). In particular, all `return` statements in the body of a get accessor shall specify an expression that is implicitly convertible to the property type. Furthermore, the endpoint of a get accessor shall not be reachable.
3110
3114
@@ -4406,6 +4410,7 @@ constructor_initializer
4406
4410
4407
4411
constructor_body
4408
4412
:block
4413
+
|'=>'expression';'
4409
4414
|';'
4410
4415
;
4411
4416
```
@@ -4422,7 +4427,12 @@ Each of the types referenced in the *formal_parameter_list* of an instance const
4422
4427
4423
4428
The optional *constructor_initializer* specifies another instance constructor to invoke before executing the statements given in the *constructor_body* of this instance constructor. This is described further in [§14.11.2](classes.md#14112-constructor-initializers).
4424
4429
4425
-
When a constructor declaration includes an `extern` modifier, the constructor is said to be an ***external constructor***. Because an external constructor declaration provides no actual implementation, its *constructor_body* consists of a semicolon. For all other constructors, the *constructor_body* consists of a *block*, which specifies the statements to initialize a new instance of the class. This corresponds exactly to the *block* of an instance method with a `void` return type ([§14.6.11](classes.md#14611-method-body)).
4430
+
When a constructor declaration includes an `extern` modifier, the constructor is said to be an ***external constructor***. Because an external constructor declaration provides no actual implementation, its *constructor_body* consists of a semicolon. For all other constructors, the *constructor_body* consists of either
4431
+
4432
+
- a *block*, which specifies the statements to initialize a new instance of the class; or
4433
+
- an expression body, which consists of `=>` followed by an *expression* and a semicolon, and denotes a single expression to initialize a new instance of the class.
4434
+
4435
+
A *constructor_body* that is a *block* or expression body corresponds exactly to the *block* of an instance method with a `void` return type ([§14.6.11](classes.md#14611-method-body)).
4426
4436
4427
4437
Instance constructors are not inherited. Thus, a class has no instance constructors other than those actually declared in the class, with the exception that if a class contains no instance constructor declarations, a default instance constructor is automatically provided ([§14.11.5](classes.md#14115-default-constructors)).
@@ -4678,7 +4689,12 @@ A *static_constructor_declaration* may include a set of *attributes* ([§21](att
4678
4689
4679
4690
The *identifier* of a *static_constructor_declaration* shall name the class in which the static constructor is declared. If any other name is specified, a compile-time error occurs.
4680
4691
4681
-
When a static constructor declaration includes an `extern` modifier, the static constructor is said to be an ***external static constructor***. Because an external static constructor declaration provides no actual implementation, its *static_constructor_body* consists of a semicolon. For all other static constructor declarations, the *static_constructor_body* consists of a *block*, which specifies the statements to execute in order to initialize the class. This corresponds exactly to the *method_body* of a static method with a `void` return type ([§14.6.11](classes.md#14611-method-body)).
4692
+
When a static constructor declaration includes an `extern` modifier, the static constructor is said to be an ***external static constructor***. Because an external static constructor declaration provides no actual implementation, its *static_constructor_body* consists of a semicolon. For all other static constructor declarations, the *static_constructor_body* consists of either
4693
+
4694
+
- a *block*, which specifies the statements to execute in order to initialize the class; or
4695
+
- an expression body, which consists of `=>` followed by an *expression* and a semicolon, and denotes a single expression to execute in order to initialize the class.
4696
+
4697
+
A *static_constructor_body* that is a *block* or expression body corresponds exactly to the *method_body* of a static method with a `void` return type ([§14.6.11](classes.md#14611-method-body)).
4682
4698
4683
4699
Static constructors are not inherited, and cannot be called directly.
4684
4700
@@ -4820,6 +4836,7 @@ finalizer_declaration
4820
4836
4821
4837
finalizer_body
4822
4838
:block
4839
+
|'=>'expression';'
4823
4840
|';'
4824
4841
;
4825
4842
```
@@ -4830,7 +4847,12 @@ A *finalizer_declaration* may include a set of *attributes* ([§21](attributes.m
4830
4847
4831
4848
The *identifier* of a *finalizer_declarator* shall name the class in which the finalizer is declared. If any other name is specified, a compile-time error occurs.
4832
4849
4833
-
When a finalizer declaration includes an `extern` modifier, the finalizer is said to be an ***external finalizer***. Because an external finalizer declaration provides no actual implementation, its *finalizer_body* consists of a semicolon. For all other finalizers, the *finalizer_body* consists of a *block*, which specifies the statements to execute in order to finalize an instance of the class. A *finalizer_body* corresponds exactly to the *method_body* of an instance method with a `void` return type ([§14.6.11](classes.md#14611-method-body)).
4850
+
When a finalizer declaration includes an `extern` modifier, the finalizer is said to be an ***external finalizer***. Because an external finalizer declaration provides no actual implementation, its *finalizer_body* consists of a semicolon. For all other finalizers, the *finalizer_body* consists of either
4851
+
4852
+
- a *block*, which specifies the statements to execute in order to finalize an instance of the class.
4853
+
- or an expression body, which consists of `=>` followed by an *expression* and a semicolon, and denotes a single expression to execute in order to finalize an instance of the class.
4854
+
4855
+
A *finalizer_body* that is a *block* or expression body corresponds exactly to the *method_body* of an instance method with a `void` return type ([§14.6.11](classes.md#14611-method-body)).
4834
4856
4835
4857
Finalizers are not inherited. Thus, a class has no finalizers other than the one that may be declared in that class.
0 commit comments