LINQ to Object

Share on TwitterShare on TumblrSubmit to StumbleUponSave on DeliciousDigg This

In this article we will see how we LINQ can be used with class objects.


LINQ –  Language Integrated Query a flexible query like language introduced in C# to query any data set, whether database, XML, or just plain objects.

We will see some samples on how LINQ queries can be used to query Object collections.

1. First we will create couple of class objects

2. Let us populate some data in the objects

3. Now let us query the emp data using LINQ.

4. Now let us sort the emp data based on Age.

5. Now Let us sort the emp data based on multiple columns Ename and Age

6. Let us now filter the emp data based on Ename.

7. Let us now filter data based on multiple conditions

8. Let us use joins between Emp and Dept objects

You see how simple it is to use LINQ with class objects. Similarly we can use many such LINQ queries on class objects.

Hope you all will get benefit out of this. Do share your comments and or feedback.