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,
Where make perfect sense. Much more than
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.
Select seemed little confusing for me too, but it was only a matter of time. Mehrdad tells you a good reason for
Select. Other than that I feel
Select conveys the immutability aspect of
Linq much better. Not that
Map would mean it's mutating the original structure, but
Select 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 call
collection.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 the
Linq namings, now I feel MS team has got it the most correct.
- Why is the LINQ "apply-to-all" method named Select?
- Why Select method of linq to EF sorting the output list?
- Why the extension method of where for LINQ in this code would print out a single number while it shouldn't print anything at all?
- Why the LINQ method `Where` in my code is wrong for string?
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Why LINQ to Entities does not recognize the method 'System.String ToString()?
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- Is it possible to ignore a list item using the Skip method of the LINQ then apply skip on the list without losing that item?
- How merge expression in the Select method with Linq
- How to apply a function to every element in a list using Linq in C# like the method reduce() in python?
- Using Linq to merge all List returned by the method of an object in a List
- Why I cannot use the Linq Where clause in a method of a public abstract class?
- How apply a method to all list members using very short linq with lambda omitted?
- Avoiding duplicate code in Linq Select method
- Linq statement to select strings containing all of the letters
- passing linq select query to the method
- C# LINQ - Select statement that compares all properties of a class with a different instance of the same class?
- LINQ to Entities does not recognize the method 'System.Linq.IQueryable in nested select
- What is the difference between creating a new object inside select LINQ clause and inside a method
- C# Linq to select multiple columns by group and apply sum(aggregate function) on value field at the same time
- The Same instance of a list for all elements when using Select New List<> in linq to sql
- Can someone tell me why this simple bit of c# code won't work, involves recursively calling method from within itself to get the root category ID
- Why did I get an exception "Cannot implicitly convert type 'bool' to 'long?'" when using the LINQ Sum method and how to fix it?
- Why does this linq extension method hit the database twice?
- Why isn't the IEnumerable returned from LINQ Where() method wholly consumed by Count()?
- LINQ to Entities does not recognize the method inside the select section
- How to write aggregate query in LINQ reusing part of the select code
- Why does this linq query fail when I change the select clause to select new Model
- Adding a second query inside the SELECT of a LINQ to Entities query gives Not Recognized Method error
More Query from same tag
- Select result of where clause
- Remove Duplicates from dropdown using Linq
- Changing method from Dictionary to Struct
- serialized property to complex type in dto with linq and automapper
- create some sort of loop inside linq query
- C# EF Linq bitwise question
- LINQ .Select() is quite slow
- generating xml from object tree issue
- What is the preferred way to interact with WMI using LINQ
- Filter a nested collections with LINQ "Include"
- LINQ queries vs Stored procedures
- Count startswith with linq
- c# delete a List from a List<List<>>
- @Html.Action is mirrioring my website from a partial view with no reference to the layout page?
- Sorting list with linq by multiple parameters
- LINQ and Grouping from a simple SQL DB relationship
- How to read File names recursively from subfolder using LINQ
- Linq question about grouping something that can change?
- LINQ to XML parsing using attributes
- Create New List From Existing Lists Comparison
- Directory.GetFiles() performance issues
- How can I make a LINQ expression return into a class?
- How do I return multiple xml elements/ attributes with linq, and create objects with them?
- How to dynamically bind datatable to grid and wrap data in certain columns?
- Translating Linq expression in c#
- Get all properties of an object using reflection - but only the properties where the object has a value for them (not default value or null)
- SubSonic 3, build dynamic or expression at runtime
- Merge List<PartialColumn> into <List<Column> using LINQ
- prevent duplicates items listview form listbox asp.net mvc3
- Getting username from Linked tables using Linq