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
5631
-
;
5632
-
5633
-
anonymous_function_parameter_modifier
5634
-
: 'ref'
5635
-
| 'out'
5636
-
| 'in'
5621
+
: '(' parameter_list? ')'
5637
5622
;
5638
5623
5639
5624
implicit_anonymous_function_signature
@@ -5670,6 +5655,10 @@ A non-`static` local function or non-`static` anonymous function can capture sta
5670
5655
> *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*
5671
5656
<!-- markdownlint-enable MD028 -->
5672
5657
5658
+
A *lambda_expression* shall not contain any *parameter_modifier*s with the `this` modifier.
5659
+
5660
+
An *anonymous_method_expression* shall not contain any *default_argument*s or *parameter_array*s.
5661
+
5673
5662
When recognising an *anonymous_function_body* if both the *null_conditional_invocation_expression* and *expression* alternatives are applicable then the former shall be chosen.
5674
5663
5675
5664
> *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*
@@ -5731,6 +5720,8 @@ A *block* body of an anonymous function is always reachable ([§13.2](statements
@@ -5761,9 +5753,7 @@ The *anonymous_function_signature* of an anonymous function defines the names an
5761
5753
5762
5754
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.
5763
5755
5764
-
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.
5765
-
5766
-
Note also that conversion to an expression tree type, evenifcompatible, maystillfailatcompile-time ([§8.6](types.md#86-expression-tree-types)).
5756
+
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.
6146
+
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.
6157
6147
6158
6148
```csharp
6159
6149
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.
6162
+
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.
6173
6163
6174
6164
Anonymous function types are used in a few specific contexts only:
6175
6165
@@ -6181,7 +6171,7 @@ An anonymous function type exists only at compile time.
6181
6171
6182
6172
The delegate type for the anonymous function or method group with parameter types `P1, ..., Pn` and return type `R` is, as follows:
6183
6173
6184
-
- 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;
6174
+
- 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;
6185
6175
- If `R` is `void`, then the delegate type is `System.Action<P1, ..., Pn>`;
6186
6176
- Otherwise, the delegate type is `System.Func<P1, ..., Pn, R>`.
0 commit comments