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.
views:
252answers:
2
+8
A:
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.
from item in collection
where item.Value == someValue
select item.Name
is translated to:
collection.Where(item => item.Value == someValue)
.Select(item => item.Name)
it would be a little inconsistent if Select
was named Map
; something like:
collection.Filter(item => item.Value == someValue)
.Map(item => item.Name)
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
and Where
make perfect sense. Much more than Map
and Filter
.
Mehrdad Afshari
2010-01-21 22:00:31
Makes complete sense. If I really cared that much I could wrap `Where` and `Select` in extension methods.
ChaosPandion
2010-01-22 00:57:25
Good answer. I actually used "Select" without LINQ, but it's much clearer as a LINQ expression.
willem
2010-07-23 08:06:58
A:
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.
Randy Minder
2010-01-21 23:29:05