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
+37-3Lines changed: 37 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6085,12 +6085,33 @@ A record class type shall have a public constructor whose signature corresponds
6085
6085
6086
6086
At runtime the primary constructor
6087
6087
6088
-
1. Executes the instance initializers appearing in *record_body*
6089
-
1. Invokes the base record class constructor with the arguments provided in the *record_base* clause, if present
6088
+
1. Stores the value of each parameter in the corresponding generated field.
6089
+
1. Executes the instance initializers appearing in *record_body*.
6090
+
1. Invokes the base record class constructor with the arguments provided in the *record_base* clause, if present.
6091
+
6092
+
Each reference to a parameter in user code is replaced with a reference to the corresponding generated field.
6090
6093
6091
6094
If a record class has a primary constructor, any user-defined constructor, except the copy constructor, shall have an explicit `this` *constructor_initializer*.
6092
6095
6093
-
Parameters of the primary constructor as well as members of the record class are in scope within the *argument_list* of the *record_base* clause and within initializers of instance fields or properties. Instance members would be an error in these locations, but the parameters of the primary constructor would be in scope and useable and would shadow members. Static members would also be useable.
6096
+
It is an error to reference a primary constructor parameter if the reference does not occur within one of the following:
Awarningshallbeissuedontheusageofanidentifier when a base member shadows a primary constructor parameter if that primary constructor parameter was not passed to the base type via its constructor.
6152
+
6153
+
Aprimaryconstructorparameterisconsideredtobepassedtothebasetypeviaitsconstructor when all the following conditions are true for an argument in *class_base*:
For each parameter of a positional *record_declaration* ([§15.2.1](classes.md#1521-general)) there shall be a corresponding public property member whose name and type are taken from the value parameter declaration.
0 commit comments