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
A *class_declaration* consists of an optional set of *attributes* ([§23](attributes.md#23-attributes)), followed by an optional set of *class_modifier*s ([§15.2.2](classes.md#1522-class-modifiers)), followed by an optional `partial` modifier ([§15.2.7](classes.md#1527-partial-type-declarations)), followed by a *class_tag* and an *identifier* that names the class, followed by an optional *type_parameter_list* ([§15.2.3](classes.md#1523-type-parameters)), followed by an optional *delimited_parameter_list* ([§15.6.2.1](classes.md#15621-general)), followed by an optional *class_base* specification ([§15.2.4](classes.md#1524-class-base-specification)), followed by an optional set of *type_parameter_constraints_clause*s ([§15.2.5](classes.md#1525-type-parameter-constraints)), followed by a *class_body* ([§15.2.6](classes.md#1526-class-body)), optionally followed by a semicolon.
28
+
There are two kinds of class: ***non-record class***, as declared by *non_record_class_declaration*, and ***record class***, as declared by *record_class_declaration*. A non-record class is the kind of class that C# has supported since the language’s inception. Record classes were added much later and are discussed in §rec-class. The differences between the two kinds are discussed in §rec-class-diffs.
29
+
30
+
A *non_record_class_declaration* consists of an optional set of *attributes* ([§23](attributes.md#23-attributes)), followed by an optional set of *class_modifier*s ([§15.2.2](classes.md#1522-class-modifiers)), followed by an optional `partial` modifier ([§15.2.7](classes.md#1527-partial-type-declarations)), followed by the keyword `class` and an *identifier* that names the class, followed by an optional *type_parameter_list* ([§15.2.3](classes.md#1523-type-parameters)), followed by an optional *class_base* specification ([§15.2.4](classes.md#1524-class-base-specification)), followed by an optional set of *type_parameter_constraints_clause*s ([§15.2.5](classes.md#1525-type-parameter-constraints)), followed by a *class_body* ([§15.2.6](classes.md#1526-class-body)), optionally followed by a semicolon.
29
31
30
32
A class declaration shall not supply *type_parameter_constraints_clause*s unless it also supplies a *type_parameter_list*.
31
33
32
34
A class declaration that supplies a *type_parameter_list* is a generic class declaration. Additionally, any class nested inside a generic class declaration or a generic struct declaration is itself a generic class declaration, since type arguments for the containing type shall be supplied to create a constructed type ([§8.4](types.md#84-constructed-types)).
33
35
34
-
If *class_tag* contains `record`, that class is a ***record class***; otherwise, it is a ***non-record class***.
35
-
36
-
For a record class, *class_modifier* shall not be `static`.
37
-
38
-
*delimited_parameter_list* shall not be present in a non-record class.
39
-
40
-
A *class_declaration* having a *delimited_parameter_list* declares a ***positional record class***.
41
-
42
-
At most only one partial type declaration of a partial record class may provide a *delimited_parameter_list*.
43
-
44
-
Parameters in *delimited_parameter_list* shall not have `ref`, `out` or `this` modifiers; however, `in` and `params` modifiers are permitted.
*base_argument_list* is discussed in §rec-class-class-base-specification.
193
+
206
194
A record class may not inherit from a non-record class other than `object`, and a non-record class may not inherit from a record class.
207
195
208
196
It is an error for *class_base* to have a *base_argument_list* if the corresponding *class_declaration* does not contain a *delimited_parameter_list*.
@@ -774,15 +762,10 @@ The *class_body* of a class defines the members of that class.
774
762
775
763
```ANTLR
776
764
class_body
777
-
: '{' class_member_declaration* '}' ';'?
778
-
|';'
765
+
: '{' class_member_declaration* '}'
779
766
;
780
767
```
781
768
782
-
A non-record class shall not have a *class_body* of `;`.
783
-
784
-
For a record class, the *class_body*s `{}`, `{};`, and `;` are equivalent. They all indicate that the only members are those synthesized by the compiler (§synth-members).
785
-
786
769
### 15.2.7 Partial type declarations
787
770
788
771
The modifier `partial` is used when defining a class, struct, or interface type in multiple parts. The `partial` modifier is a contextual keyword ([§6.4.4](lexical-structure.md#644-keywords)) and has special meaning in a *class_declaration*, a *struct_declaration*, or an *interface_declaration*. (A partial type may contain partial method declarations ([§15.6.9](classes.md#1569-partial-methods)).
@@ -849,7 +832,7 @@ The handling of attributes specified on the type or type parameters of different
849
832
850
833
### 15.3.1 General
851
834
852
-
Themembersofaclassconsist of the members introduced by its *class_member_declaration*s and the members inherited from the direct base class. For a record class, the member set also includes the synthesized members generated by the compiler (§synth-members).
835
+
Themembersofaclassconsist of the members introduced by its *class_member_declaration*s and the members inherited from the direct base class.
853
836
854
837
```ANTLR
855
838
class_member_declaration
@@ -937,10 +920,6 @@ The set of members of a type declared in multiple parts ([§15.2.7](classes.md#1
Eachclassdeclarationhasanassociated ***instancetype***. Foragenericclassdeclaration, theinstancetypeisformedbycreatingaconstructedtype ([§8.4](types.md#84-constructed-types)) fromthetypedeclaration, witheachofthesuppliedtypeargumentsbeingthecorrespondingtypeparameter. Sincetheinstancetypeusesthetypeparameters, itcanonlybeusedwherethetypeparametersareinscope; thatis, insidetheclassdeclaration. The instance type is the type of `this` for code written inside the class declaration. For non-generic classes, the instance type is simply the declared class.
@@ -4925,8 +4904,6 @@ Instance constructors are not inherited. Thus, a class has no instance construct
4925
4904
4926
4905
Instance constructors are invoked by *object_creation_expression*s ([§12.8.17.2](expressions.md#128172-object-creation-expressions)) and through *constructor_initializer*s.
4927
4906
4928
-
A positional record class ([§15.2.1](classes.md#1521-general)) has a synthesized primary constructor; see §rec-class-pos-mem-pricon for more information.
4929
-
4930
4907
### 15.11.2 Constructor initializers
4931
4908
4932
4909
All instance constructors (except those for class `object`) implicitly include an invocation of another instance constructor immediately before the *constructor_body*. The constructor to implicitly invoke is determined by the *constructor_initializer*:
@@ -5147,39 +5124,6 @@ If overload resolution is unable to determine a unique best candidate for the ba
5147
5124
>
5148
5125
>*endexample*
5149
5126
5150
-
### §copy-constructor Copy constructors
5151
-
5152
-
A***copyconstructor***for a type `T` is a constructor having a single parameter of type `T`. The purpose of a copy constructor is to copy the state from the parameter to the new instance being created.
>therecordclassis immutable. The synthesized auto properties `Age` and `Name` are read-init. A copy constructor is synthesized, as is a primary constructor. *end example*
5180
-
5181
-
In certain circumstances (§rec-class-copyclone), a copy constructor may be synthesized by the compiler, and called by synthesized code.
0 commit comments