Ordering Operators in LINQ

Ordering Operators in LINQ

In this article, I am going to discuss the Ordering Operators in LINQ with examples. Please read our previous article where we discussed the Union Method in C# with examples. At the end of this article, you will learn the following two things.

Ordering Operators in LINQ

What Are Ordering Operators?

In simple terms, we can say that Ordering is nothing but a process to manage the data in a particular order. It is not changing the data or output rather this operation arranges the data in a particular order i.e. either ascending order or descending order.

In this case, the count is going to be the same but the order of the element is going to change.

We sort the data in two ways i.e. ascending or descending order. The order may be integer-based or any other data type based. For example

  1. Name of Cities of a particular state in alphabetical order.
  2. Students order by Roll Number in a class.

It is also possible to order based on multiple columns like Employee First and Last Name in ascending order while the Salary is on descending order.

What are the Methods available in Linq for Sorting the data?

There are five methods provided by LINQ to sort the data. They are as follows

  1. OrderBy
  2. OrderByDescending
  3. ThenBy
  4. ThenByDescending
  5. Reverse

In the next article, I am going to discuss the LINQ OrderBy Method with examples.