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-7Lines changed: 26 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2296,7 +2296,7 @@ parameter_modifier
2296
2296
;
2297
2297
2298
2298
parameter_mode_modifier
2299
-
: 'ref'
2299
+
: ref_kind
2300
2300
| 'out'
2301
2301
| 'in'
2302
2302
;
@@ -2308,13 +2308,13 @@ parameter_array
2308
2308
2309
2309
The parameter list consists of one or more comma-separated parameters of which only the last may be a *parameter_array*.
2310
2310
2311
-
A *fixed_parameter* consists of an optional set of *attributes* ([§23](attributes.md#23-attributes)); an optional `this` modifier; an optional `scoped` modifier; an optional `in`, `out`, `ref` modifier; a *type*; an *identifier*; and an optional *default_argument*. Each *fixed_parameter* declares a parameter of the given type with the given name. The `this` modifier designates the method as an extension method and is only allowed on the first parameter of a static method in a non-generic, non-nested static class. If the parameter is a `struct` type or a type parameter constrained to a `struct`, the `this` modifier may be combined with either the `ref` or `in` modifier, but not the `out` modifier. Extension methods are further described in [§15.6.10](classes.md#15610-extension-methods). A *fixed_parameter* with a *default_argument* is known as an ***optional parameter***, whereas a *fixed_parameter* without a *default_argument* is a ***required parameter***. A required parameter shall not appear after an optional parameter in a *parameter_list*.
2311
+
A *fixed_parameter* consists of an optional set of *attributes* ([§23](attributes.md#23-attributes)); an optional `this` modifier; an optional `scoped` modifier; an optional `in`, `out`, `ref` modifier, or `ref readonly`; a *type*; an *identifier*; and an optional *default_argument*. Each *fixed_parameter* declares a parameter of the given type with the given name. The `this` modifier designates the method as an extension method and is only allowed on the first parameter of a static method in a non-generic, non-nested static class. If the parameter is a `struct` type or a type parameter constrained to a `struct`, the `this` modifier may be combined with the `ref`, `ref readonly`, or `in` modifier, but not the `out` modifier. Extension methods are further described in [§15.6.10](classes.md#15610-extension-methods). A *fixed_parameter* with a *default_argument* is known as an ***optional parameter***, whereas a *fixed_parameter* without a *default_argument* is a ***required parameter***. A required parameter shall not appear after an optional parameter in a *parameter_list*.
2312
2312
2313
2313
An output parameter implicitly has the `scoped` modifier.
2314
2314
2315
2315
For a discussion of `scoped`, see [§9.7.3](variables.md#973-the-scoped-modifier).
2316
2316
2317
-
A parameter with a `ref`, `out` or `this` modifier cannot have a *default_argument*. An input parameter may have a *default_argument*. The *expression* in a *default_argument* shall be one of the following:
2317
+
A parameter with a `ref`, `out` or `this` modifier cannot have a *default_argument*. A parameter with an `ref readonly` or `in` modifier may have a *default_argument*; however, in the `ref readonly` case, a warning shall be issued. The *expression* in a *default_argument* shall be one of the following:
2318
2318
2319
2319
- a *constant_expression*
2320
2320
- an expression of the form `new S()` where `S` is a value type
@@ -2358,9 +2358,10 @@ The following kinds of parameters exist:
>*Note*:Asdescribedin [§7.6](basic-concepts.md#76-signatures-and-overloading), the `in`, `out`, and `ref` modifiersarepartofamethod’ssignature, butthe `params` and `scoped` modifiersarenot. *endnote*
2364
+
>*Note*:Asdescribedin [§7.6](basic-concepts.md#76-signatures-and-overloading), the `in`, `out`, `ref`, and `refreadonly` modifiersarepartofamethod’ssignature, butthe `params` and `scoped` modifiersarenot. *endnote*
2364
2365
2365
2366
#### 15.6.2.2 Value parameters
2366
2367
@@ -2380,11 +2381,11 @@ Input, output, and reference parameters are ***by-reference parameter***s. A by-
@@ -2396,7 +2397,11 @@ It is a compile-time error to modify the value of an input parameter.
2396
2397
2397
2398
##### 15.6.2.3.3 Referenceparameters
2398
2399
2399
-
Aparameterdeclaredwitha `ref` modifierisa ***referenceparameter***. Fordefinite-assignmentrules, see [§9.2.6](variables.md#926-reference-parameters).
2400
+
Aparameterdeclaredwitha `ref` or `refreadonly` modifierisa ***referenceparameter***. Fordefinite-assignmentrules, see [§9.2.6](variables.md#926-reference-parameters).
@@ -2456,6 +2461,20 @@ A parameter declared with a `ref` modifier is a ***reference parameter***. For d
2456
2461
>theinvocationof `F` in `G` passesareferenceto `s` for both `a` and `b`. Thus, for that invocation, the names `s`, `a`, and `b` all refer to the same storage location, and the three assignments all modify the instance field `s`.
>showsalargestructbeing passed by reference for efficiency, but without the called method having the ability to modify that that struct. *end example*
2459
2478
2460
2479
For a `struct` type, within an instance method, instance accessor ([§12.2.1](expressions.md#1221-general)), or instance constructor with a constructor initializer, the `this` keyword behaves exactly as a reference parameter of the struct type ([§12.8.14](expressions.md#12814-this-access)).
0 commit comments