Here we will learn linq sorting operations / operators in c#, vb.net with examples and different type of sorting operators (order by, order by descending, then by, then by descending and reverse) to sort data in linq with examples.
In LINQ sorting operators are used to change the order or sequence of data (either ascending or descending) based on one or more attributes. Following are the different type of sorting operators available in LINQ.
These sorting operators are used to sort the data. But the last operator REVERSE simply reverses the items in the collection. Rest of the operators are used to orders the data just like we use Order by clause in SQL. These sorting operators are similar to what we do in SQL but only the difference is we are using these operators in LINQ.
Following table shows the more detailed information related to sorting operators in LINQ.
|OrderBy||This operator will sort values in ascending order.||orderby|
|OrderByDescending||This operator will sort values in descending order.||orderby .... descending|
|ThenBy||This operator is used to perform secondary sorting in ascending order.||orderby ... , ...|
|ThenByDescending||This operator is used to perform sorting in descending order.||orderby ... , ... descending|
|Reverse||This operator is used to reverse order of elements in collection.||Not Applicable.|
In coming chapters we will learn all these sorting operators in detail.