0

I have a list of structures, where my struct looks like this:

struct coordinate
{
  int x;
  int y;
} 

I want the list sorted initialy by the x value of the struct, and if there are(from the sorted structs) structs with the same x (like coordinate[1].x = coordinate[2].x), sort it then by y. It's possible in C#? I've already sorted them by x

List.Sort((s1, s2) => s1.x.CompareTo(s2.x));

but I dont know how to make the second step. please help :)

monfort
  • 183
  • 1
  • 2
  • 10
  • 2
    `var sortedList = list.OrderBy(r=> r.x).ThenBy(r=> r.y).ToList();` – Habib Jun 01 '15 at 20:10
  • In the marked duplicate, the [second answer](http://stackoverflow.com/a/2779462/414076) (based on current votes) gives you the inline sort that matches your question. If you prefer producing a *new* ordered list, then the first answer is applicable. – Anthony Pegram Jun 01 '15 at 20:14

0 Answers0