_=> what does this underscore mean in Lambda expressions?
What does an lambda expression like _=> expr
mean?
What is the purpose of _
as input to lambda?
Example:
int count = 0;
list.ForEach(_ => count += 1);
Solution 1:
That is a convention used when you don't care about the parameter.
Solution 2:
It is a parameter name, albeit not a useful one, but it's the one typically used (by some conventions) when you need to specify that the expression has a parameter in order to get the code to compile, but you don't really care about it, so you're just going to ignore it.
It's basically exploiting the syntax for what a legal identifier in C# constitutes, and since an identifier can start with an underscore, and contain nothing else, it's just a parameter name.
You could just have easily have written:
var _ = 10;