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",salaty=2500});
lst.add(new person{ID=2,Name="Sena",salaty=1500});
lst.add(new person{ID=3,Name="Max",salaty=5500});
lst.add(new person{ID=4,Name="Gen",salaty=3500});
now i want to query the above list with linq. please guide me with sample code.
Well, the code you've given is invalid to start with -
List
is a generic type, and it has anAdd
method instead ofadd
etc.But you could do something like:
If you want to learn details of what all the LINQ operators do, and how they can be implemented in LINQ to Objects, you might be interested in my Edulinq blog series.
Since you haven't given any indication to what you want, here is a link to 101 LINQ samples that use all the different LINQ methods: 101 LINQ Samples
Also, you should really really really change your
List
into a strongly types list (List<T>
), and properly define T, and add instances of T to your list. It will really make the queries much easier since you don't have to cast everything all the time.I would also suggest LinqPad as a convenient way to tackle with Linq for both advanced and beginners.
Example:
![enter image description here](https://i.stack.imgur.com/NFsiB.png)