Possible Duplicate:
Multiple “order by” in LINQ
I have a list of orders and I need to order it by the date of the order and then a secondary sort by the price of the order. I'm not sure how exactly to do this since I tried orders.OrderBy(o => o.Date).OrderBy(o => o.Price), but it doesn't work. Any help is much appreciated. Thank you
You want to use the ThenBy function:
orders.OrderBy(o => o.Date).ThenBy(o => o.Price)
The other option is to use the LINQ query syntax instead of the method syntax:
List<Order> sortedOrders = from o in orders
orderby o.Date, O.Price
select o;
You can use:
orders.OrderBy(o => o.Date).ThenBy(o => o.Price)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With