Javatpoint Logo
Javatpoint Logo

LINQ ThenBy Descending Operator

In LINQ, ThenByDescending operator is used to implement the sorting on multiple fields in the list/ collection, and by default, ThenByDescending operator will sort the list of items in descending order. In LINQ, we use the ThenByDescending operator along with OrderBy operator.

In LINQ, ThenByDescending operator is used to specify the second sorting condition to be the descending, and OrderBy operator is used to specify the condition on primary sorting.

Syntax of LINQ ThenByDescending operator

The Syntax of using the LINQ ThenByDescending Operator to implement the sorting on list/collection of the items along with OrderBy operator.

C# Code

From the above example, it shows that we defined first the sorting condition wiith OrderBy Operator and second condition with ThenByDescending operator. We are sorting the list of items using "Name" and we added another field "RoleId" by using ThenByDescending Operator.

We will see with the help of an example.

Example of LINQ ThenByDescending operator

Here is the example of LINQ ThenByDescending operator to sort the list/collection of items based on the multiple fields is:

In the above example, we are sorting the "ObjStudent" list of items by using the multiple fields Name, RoleId.

OUTPUT:

LINQ ThenBy Descending Operator




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA