Projection Using the Select Clause

Now that we’ve identified the query sources, we can start operating on the data they provide. Although you might think of filtering and ordering as the first kind of operations you want to perform, we’ll start from the end. Every query expression in C# needs to end either by a select clause or a group by clause. The former operation is the simplest to explain, so we start from there.

Identity Projection

The most trivial projection possible doesn’t do any transformation on the input data and is called the identity projection, after the identity function. An example is shown here:

var nums = new List<int> { 1, 2, 3, 4, 5 };var res = from n in nums          select n;

This produces ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.