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