In LINQ, projection is an operation which converts an object into the new form which holds only those properties that will be subsequently used. By using projection, a developer can create a new type which is built from each object. You are allowed to project property and conduct mathematical function on it, and you can also project the original object without transforming it.
In LINQ, the following projection operations are available:
- Select
- SelectMany
Select Operator
The select operator returns the IEnumerator collection, which holds the items based on a transformation function. Or in other words, we can say that select operator is used when you want to select a single value from the given collection.
Select using Query Syntax: In LINQ, a Select operator is used in creating a query using query syntax. In the query expression, the expression ends with Select or GroupBy clause. In a query, the select operator is used to return the collection of the custom class or anonymous type that include the properties as per the need of the user and also used to manipulate the result according to the user need. Select operator support query syntax in both C# and
VB.NET language As shown in the below examples:
Example:
Output:
Employee Name: Anjita
Employee Name: Soniya
Employee Name: Rohit
Employee Name: Supriya
Employee Name: Anil
Employee Name: Anju
Select using Method Syntax: In method syntax, the select operator is optional, you may use it to shape the data. The Select method is present in both the Queryable and Enumerable class. It supports method syntax in both C# and VB.Net languages. The use of the select method is shown in the below examples.
Example: