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:
ThenBy operator is used to implementing secondary sort in ascending order. The multiple sorting is supported by ThenBy operator. Generally, ThenBy method is used with the OrderBy method. The OrderBy() Method, first sort the elements of the sequence or collection in ascending order after that ThenBy() method is used to again sort the result of OrderBy() method in ascending 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 ThenBy 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 as shown in Example 1.
- It is implemented by using deferred execution.
Employee Name: Anil Gender: Male Employee Name: Anjita Gender: Female Employee Name: Anju Gender: Female Employee Name: Rohit Gender: Male Employee Name: Soniya Gender: Female Employee Name: Supriya Gender: Female
Employee Name: Anil Salary: 40000 Employee Name: Anjita Salary: 20000 Employee Name: Anju Salary: 50000 Employee Name: Rohit Salary: 40000 Employee Name: Soniya Salary: 30000 Employee Name: Supriya Salary: 40000
- LINQ | Sorting Operator | OrderBy
- LINQ | Sorting Operator | Reverse
- LINQ | Sorting Operator | ThenByDescending
- LINQ | Sorting Operator | OrderByDescending
- LINQ | Set Operator | Except
- LINQ | Element Operator | First
- LINQ | Partition Operator | Take
- LINQ | Quantifier Operator | All
- LINQ | Set Operator | Intersect
- LINQ | Set Operator | Distinct
- LINQ | Quantifier Operator | Any
- LINQ | Quantifier Operator | Contains
- LINQ | Set Operator | Union
- LINQ | Element Operator | Last
- LINQ | Filtering Operator | where
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.