A simple select is classified under Projection Operators in LINQ. Below is a sample that just selects the array of numbers from an array using LINQ Select statement
public void Linq()
{
int[] numbers = { 1, 2, 3 };
var selctedNumbers =
from n in numbers
select n;
Console.WriteLine("Selected Numbers:");
foreach (var i in selctedNumbers)
{
Console.WriteLine(i);
}
}
Result
Numbers: 1 2 3
Below is a sample to select to return a sequence of just the names of a list of Employees using LINQ Select statement
public void Linq()
{
List Employees = GetEmployeeList();
var employeeNames =
from e in Employees
select e.EmployeeName;
Console.WriteLine("Employee Names:");
foreach (var employeeName in employeeNames)
{
Console.WriteLine(employeeName);
}
}
Result
Employee Names: David Ajith Susan