Search code examples
c#linq-to-objects

how to query LIST using linq


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.


Solution

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

    Example:
    enter image description here