When I read code that uses Select
I think "select-all-where".
When I read code that uses Map
I think "this-to-that" or "apply-to-all".
I can't be the only person that feels the name Select
is confusing.
相关问题
- Check if tie in count of lists using linq
- Trouble with OR in Sharepoint CAML
- get key value pairs from xml using linq
- query and create objects with a one to many relati
- select column from dataset using LINQ
相关文章
- 想问问Linq中有没有根据条件选择要不要关联表。
- Why do I need a ToList() to avoid disposed context
- LINQ .Include() properties from sub-types in TPH i
- Can a method chain be called LINQ?
- Get grouped comma separated values with linq
- How does a LINQ expression know that Where() comes
-
Creating dynamic Expression
> - Entity Framework - An item with the same key has a
At first
Select
seemed little confusing for me too, but it was only a matter of time. Mehrdad tells you a good reason forSelect
. Other than that I feelSelect
conveys the immutability aspect ofLinq
much better. Not thatMap
would mean it's mutating the original structure, butSelect
states it much clearer. It tells you're not touching the original list but merely selecting from it to form another list.It goes with other naming as well like
Where
. When you callcollection.Filter
it gives you an idea that you're filtering on that particular collection, or at least the first time. In the end it's all a matter of getting familiarized. Though in the beginning I was so annoyed by theLinq
namings, now I feel MS team has got it the most correct.One of the major reasons Select comes last is to make Intellisense work. By putting the source of the sequence first (from statement), Intellisense can work properly.
It's really identical to map from functional languages. The reason it's named
Select
is that it's designed to be used as a part of LINQ which uses SQL-like keywords.is translated to:
it would be a little inconsistent if
Select
was namedMap
; something like:In fact, many people use LINQ without having heard of functional programming at all. To them, LINQ is a method to retrieve data objects and query them easily (like SQL queries are). To them,
Select
andWhere
make perfect sense. Much more thanMap
andFilter
.