C# – LINQ – Where, OrderBy, Select

In the current code, we simply show how to use “OrderBy”, “Select” and “Where” in LINQ. If you want to know more about LINQ, you should refer to here. This time Microsoft has written a really good article about this. Anyway, long story short, LINQ means Language-Integrated Query, which introduces patterns for quering and updating data. If you have some experience with SQL, then LINQ is the SQL of C# (my understanding about it…).

Here is our code:

The output of the code is the following picture:



What the code does?

1. It gets a string named with the beautiful name “names”.

2. Then we make an IEnumerable named query and we fill it up with “names”.

3. On this IEnumerable we put the three filters – “where”, “orderby” and “select”. With “Select” we use “ToUpper”, in order to make the results with upper case.

4. Finally we print the elements with a foreach loop.