LINQ Take Query Operator

By Peter Bromberg

Use the Take<TSource> operator to return a given number of elements in a sequence and then skip over the remainder.

IQueryable<Employee> firstHiredQuery =
    (from emp in db.Employees
    orderby emp.HireDate
    select emp)
    .Take(5);

foreach (Employee empObj in firstHiredQuery)
{
   Console.WriteLine("{0}, {1}", empObj.EmployeeID,
        empObj.HireDate);
}

LINQ Take Query Operator  (884 Views)