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
: attributes? 'scoped'? anonymous_function_parameter_modifier? type identifier
5626
-
;
5627
-
5628
-
anonymous_function_parameter_modifier
5629
-
: 'ref'
5630
-
| 'out'
5631
-
| 'in'
5616
+
: '(' parameter_list? ')'
5632
5617
;
5633
5618
5634
5619
implicit_anonymous_function_signature
@@ -5665,6 +5650,10 @@ A non-`static` local function or non-`static` anonymous function can capture sta
5665
5650
> *Note*: A `static` anonymous function is not required to produce the same delegate instance on each evaluation. See [§10.7.2](conversions.md#1072-evaluation-of-anonymous-function-conversions-to-delegate-types). *end note*
5666
5651
<!-- markdownlint-enable MD028 -->
5667
5652
5653
+
A *lambda_expression* shall not contain any *parameter_modifier*s with the `this` modifier.
5654
+
5655
+
An *anonymous_method_expression* shall not contain any *default_argument*s or *parameter_array*s.
5656
+
5668
5657
When recognising an *anonymous_function_body* if both the *null_conditional_invocation_expression* and *expression* alternatives are applicable then the former shall be chosen.
5669
5658
5670
5659
> *Note*: The overlapping of, and priority between, alternatives here is solely for descriptive convenience; the grammar rules could be elaborated to remove the overlap. ANTLR, and other grammar systems, adopt the same convenience and so *anonymous_function_body* has the specified semantics automatically. *end note*
@@ -5726,6 +5715,8 @@ A *block* body of an anonymous function is always reachable ([§13.2](statements
@@ -5756,9 +5748,7 @@ The *anonymous_function_signature* of an anonymous function defines the names an
5756
5748
5757
5749
Ifananonymousfunctionhasan*explicit_anonymous_function_signature*, thenthesetofcompatibledelegate types and expression tree types is restricted to those that have the same parameter types and modifiers in the same order ([§10.7](conversions.md#107-anonymous-function-conversions)). Incontrasttomethodgroupconversions ([§10.8](conversions.md#108-method-group-conversions)), contra-varianceofanonymousfunctionparametertypesisnotsupported. Ifananonymousfunctiondoesnothavean *anonymous_function_signature*, thenthesetofcompatibledelegate types and expression tree types is restricted to those that have no output parameters.
5758
5750
5759
-
Note that an *anonymous_function_signature* cannot include a parameter array. Nevertheless, an*anonymous_function_signature*maybecompatiblewithadelegate type whose parameter list contains a parameter array.
5760
-
5761
-
Note also that conversion to an expression tree type, evenifcompatible, maystillfailatcompile-time ([§8.6](types.md#86-expression-tree-types)).
5751
+
Note that conversion to an expression tree type, evenifcompatible, maystillfailatcompile-time ([§8.6](types.md#86-expression-tree-types)).
A method group has a natural type if all candidate methods (including extension methods) in the method group have a common signature.
6141
+
A method group has a natural type if all candidate methods (including extension methods) in the method group have a common signature including default values and `params` modifiers.
6152
6142
6153
6143
```csharp
6154
6144
varread=Console.Read; // Just one overload; Func<int> inferred
The natural type of an anonymous function expression or method group is called an ***anonymous function type***. An anonymous function type represents a method signature: the parameter types and ref kinds, and the return type and ref kind. Anonymous function expressions or method groups with the same signature have the same anonymous function type.
6157
+
The natural type of an anonymous function expression or method group is called an ***anonymous function type***. An anonymous function type represents a method signature: the parameter types and ref kinds, default values, `params` modifiers, and the return type and ref kind. Anonymous function expressions or method groups with the same signature have the same anonymous function type.
6168
6158
6169
6159
Anonymous function types are used in a few specific contexts only:
6170
6160
@@ -6176,7 +6166,7 @@ An anonymous function type exists only at compile time.
6176
6166
6177
6167
The delegate type for the anonymous function or method group with parameter types `P1, ..., Pn` and return type `R` is, as follows:
6178
6168
6179
-
- If any parameter or return value is not by value, or there are more than 16 parameters, or any of the parameter types or return type are not valid type arguments (e.g., `(int* p) => { }`), then the delegate is a synthesized `internal` anonymous delegate type with a signature that matches the anonymous function or method group, and with parameter names `arg1, ..., argn`, or `arg` if a single parameter;
6169
+
- If any parameter or return value is not by value, or any parameter is optional or `params`, or there are more than 16 parameters, or any of the parameter types or return type are not valid type arguments (e.g., `(int* p) => { }`), then the delegate is a synthesized `internal` anonymous delegate type with a signature that matches the anonymous function or method group, and with parameter names `arg1, ..., argn`, or `arg` if a single parameter;
6180
6170
- If `R` is `void`, then the delegate type is `System.Action<P1, ..., Pn>`;
6181
6171
- Otherwise, the delegate type is `System.Func<P1, ..., Pn, R>`.
0 commit comments