128
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:
- ORDER BY
- ORDER BY DESCENDING
- THEN BY
- THEN BY DESCENDING
- REVERSE
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.
Operator | Description | Query Syntax |
---|---|---|
OrderBy | This operator will sort the values in ascending order. | ordeby |
OrderByDescending | This operator will sort the values in descending order. | Orderby ……descending |
ThenBy | This operator is used to perform the secondary sorting in ascending order. | Orderby…,…. |
ThenByDescending | This operator is used to perform the sorting in descending order. | Orderby….,….descending |
Reverse | This operator is used to reverse the order of elements in the collection. | Not applicable |
Next TopicLINQ OrderBy Operator