how to query LIST using linq

Mou picture Mou · May 31, 2011 · Viewed 109.9k times · Source

Suppose if I add person class instance to list and then I need to query the list using linq.

List lst=new List();
lst.add(new person{ID=1,Name="jhon",salary=2500});
lst.add(new person{ID=2,Name="Sena",salary=1500});
lst.add(new person{ID=3,Name="Max",salary=5500});
lst.add(new person{ID=4,Name="Gen",salary=3500});

Now I want to query the above list with linq. Please guide me with sample code.

Answer

Sorin Comanescu picture Sorin Comanescu · May 31, 2011

I would also suggest LinqPad as a convenient way to tackle with Linq for both advanced and beginners.

Example:
enter image description here