C# lambda unnamed parameters
Solution 1:
No, you can't. Looking at the C# language specification grammar, there are two ways to declare lambdas: explicit and implicit. Neither one allows you to skip the identifier of the parameter or to reuse identifiers (names).
explicit-anonymous-function-parameter:
anonymous-function-parameter-modifieropt type identifier
implicit-anonymous-function-parameter:
identifier
It's the same as for unused function parameters in ordinary functions. They have to be given a name.
Of course you can use _
as the name for one of the parameters, as it is a valid C# name, but it doesn't mean anything special.
As of C# 7, _
does have a special meaning. Not for lambda expression parameter names but definitely for other things, such as pattern matching, deconstruction, out variables and even regular assignments. (For example, you can use _
= 5; without declaring _
.)
Solution 2:
The short answer is: no, you have to name every parameter, and the names have to be unique.
You can use _
as one parameter name because it is a valid identifier in C#.
However, you can only use it once.