---
title: "How to use multiple \"order by\" in LINQ?"  
description: "How to use multiple \"order by\" in LINQ?"  
author: "Sandra Emily"  
published: 2023-08-17  
updated: 2023-08-18  
canonical: https://www.mindstick.com/forum/159562/how-to-use-multiple-order-by-in-linq  
category: "c#"  
tags: ["c#", "linq"]  
reading_time: 2 minutes  

---

# How to use multiple "order by" in LINQ?

How to use [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) "[order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) by" in [LINQ](https://www.mindstick.com/articles/12007/language-integrated-query-linq-queries)?

## Replies

### Reply by Aryan Kumar

To use multiple `OrderBy()` in LINQ, you can use the `ThenBy()` method. The `ThenBy()` method takes a lambda expression as its parameter and sorts the list by the property specified by the lambda expression. The following code sorts a list of `Person` objects by their age in ascending order, and then by their name in descending order:

C#

```plaintext
var people = new List<Person>();
people.Add(new Person { Age = 20, Name = "John" });
people.Add(new Person { Age = 30, Name = "Jane" });
people.Add(new Person { Age = 10, Name = "Peter" });

var sortedPeople = people.OrderBy(p => p.Age).ThenBy(p => p.Name);
```

In this code, the `OrderBy()` method sorts the list by the `Age` property of the `Person` objects in ascending order. The `ThenBy()` method then sorts the list by the `Name` property of the `Person` objects in descending order.

You can also use the `ThenByDescending()` method to sort the list by the property specified by the lambda expression in descending order. The following code is equivalent to the previous code:

C#

```plaintext
var sortedPeople = people.OrderBy(p => p.Age).ThenByDescending(p => p.Name);
```


---

Original Source: https://www.mindstick.com/forum/159562/how-to-use-multiple-order-by-in-linq

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
