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:
- OrderBy
- OrderByDescending
- ThenBy
- ThenByDescending
- Reverse
OrderByDescending Operator
OrderByDescending operator is used to rearranging the elements of the given sequence in descending order. It does not support query syntax in C# and VB.Net. It
only supports method syntax. If you want to rearrange or sort the elements of the given sequence or collection in descending order in query syntax, then use descending keyword as shown in below example.
And in method syntax, use
OrderByDescending () method to sort the elements of the given sequence or collection. This method is present in both the Queryable and Enumerable class. And the method syntax is supported by both C# and VB.Net languages. As shown in the below examples. The OrderByDescending method sorts the elements of the collection according to a single property, you are not allowed to sort the collection using multiple properties.
Example 1:
Output:
Employee ID: 214
Employee ID: 213
Employee ID: 212
Employee ID: 211
Employee ID: 210
Employee ID: 209
Example 2: