Based on the answers above, I think there is general consensus that, if you can't tell from the context what you are dealing with, using a descriptive name is better. For example:
entities.Where(person => person.Age >= 21);
In cases where the context is obvious, however, a single-letter name may actually help readability, because it makes it easier to focus on the critical information. For example:
people.Where(p => p.Age >= 21);
or people.Where(x => x.Age >= 21);
The question is, which is better, p
or x
?
- In favor of
p
, it's a familiar pattern in SQL queries and provides a little extra reminder that you are talking about a Person
.
- In favor of
x
, if you rename Person
to Customer
, you don't have to worry about fixing all your lambda parameters. If you had used p
, it would actually be a little confusing if your code became customers.Where(p => p.Age >= 21)
, whereas x
is basically agnostic.
I've recent started using x
, and so far, I haven't noticed any significant downside, but please comment if you disagree.