LINQ Sorting Operators (Order By / Then By / Reverse)

  Total Views : 323
  Comments : 0
 
  Keywords : How to sort data in linq using sorting operators with examples, Different type of sorting operations in linq, Linq order by / order by descending / then by / then by descending operators

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.

LINQ Sorting Operators

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.

 

  1. ORDER BY
  2. ORDER BY DESCENDING
  3. THEN BY
  4. THEN BY DESCENDING
  5. REVERSE

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.

 

OperatorDescriptionQuery Syntax
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.

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User