Posted by Alec on Thu, 17 Sep 2009, in ASP.NET C# LINQ
One of the best things of using LINQ is how easy we could sort or filter objects with a line of code. Consider we have a generic list of object of Employees and we want to filter them with their age. Using LINQ, we don't have to connect to the data source and get the SQL to do the where query. We can just do something like this:
List<Employee> employees = GetEmployeeList(); var AgedEmployees = from e in employees where e.Age > 50 select e ; ArrayList list = new ArrayList(); foreach (var i in AgedEmployees) list.Add(i);
Now, to sort them, we can just add an order by before select e.