In LINQ, sorting operators are used to rearrange the given sequence in ascending or descending order based on one or more attributes. There are 5 different types of sorting operators are available in LINQ:
The ThenByDescending operator is used to implement secondary sort in descending order. The multiple sorting is supported by ThenByDescending operator. Generally, ThenByDescending method is used with the OrderBy method. The OrderBy() method first sort the elements of the sequence or collection in descending order after that ThenByDescending() method is used to again sort the result of OrderBy() method in descending order. Or in other words, in LINQ, the collection is the first sort according to the primary field which is given by OrderBy method after that the result of the primary sort is again sorted by the secondary field that is given by the ThenByDescending method.
- It does not support query syntax in C# and VB.Net languages.
- It support method syntax in both C# and VB.Net languages.
- It present in both the Queryable and Enumerable class.
- The secondary sorting in query syntax is separated by using comma.
- It is implemented by using deferred execution.
Employee Name: Supriya Salary: 40000 Employee Name: Soniya Salary: 30000 Employee Name: Rohit Salary: 40000 Employee Name: Anju Salary: 50000 Employee Name: Anjita Salary: 20000 Employee Name: Anil Salary: 40000
Employee ID: 209 Salary: 20000 Employee ID: 210 Salary: 30000 Employee ID: 211 Salary: 40000 Employee ID: 212 Salary: 40000 Employee ID: 213 Salary: 40000 Employee ID: 214 Salary: 50000
- LINQ | Sorting Operator | OrderBy
- LINQ | Sorting Operator | OrderByDescending
- LINQ | Sorting Operator | ThenBy
- LINQ | Sorting Operator | Reverse
- LINQ | Set Operator | Except
- LINQ | Quantifier Operator | All
- LINQ | Element Operator | Last
- LINQ | Quantifier Operator | Any
- LINQ | Partition Operator | Take
- LINQ | Quantifier Operator | Contains
- LINQ | Filtering Operator | where
- LINQ | Set Operator | Union
- LINQ | Set Operator | Distinct
- LINQ | Element Operator | First
- LINQ | Set Operator | Intersect
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.