Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort a list by Code, Then by Name

I have a list of objects. I sort this list by Code by writing this line:

Result.Sort(delegate(Position p1, Position p2) { return p1.Code.CompareTo(p2.Code); });

But I want to sort this line first by Code and then by Name. How to I do this?

like image 839
Tavousi Avatar asked Dec 06 '25 20:12

Tavousi


1 Answers

Why won't you use LINQ?

var ordered = list.OrderBy(x => x.Code).ThenBy(x => x.Name).ToList();
like image 101
gdoron is supporting Monica Avatar answered Dec 08 '25 17:12

gdoron is supporting Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!