LINQ Sorting Operators (Order By, then By, Reverse)

Sorting Operators in LINQ are used to change the order or sequence of the data (either ascending or descending), which is based on one or more attributes.

Sorting Operators available in LINQ are:

  1. ORDER BY
  2. ORDER BY DESCENDING
  3. THEN BY
  4. THEN BY DESCENDING
  5. REVERSE
LINQ Sorting Operators

All these sorting operators are used to sort the data. But the REVERSE operator reverses the items in the collection. Rest operators are used to order the data just like we use Order by clause in SQL. These sorting operators are similar to SQL, but the only difference is that we are using the operators in LINQ.

From the table, it shows the detailed information related to sorting operators in SQL.

OperatorDescriptionQuery Syntax
OrderByThis operator will sort the values in ascending order.ordeby
OrderByDescendingThis operator will sort the values in descending order.Orderby ......descending
ThenByThis operator is used to perform the secondary sorting in ascending order.Orderby...,....
ThenByDescendingThis operator is used to perform the sorting in descending order.Orderby....,....descending
ReverseThis operator is used to reverse the order of elements in the collection.Not applicable





Latest Courses