问题
I have a jagged array and I need to sort it by the column "2":
example: array[x][2]
What I have is about 64 where the "x" is and in the second column (where the "2" is) I have 4 different options, but I need to sort by the second option.
回答1:
Just use OrderBy
:
array = array.OrderBy(inner => inner[2]).ToArray();
If it's important to use an in place sort then you can use Array.Sort
:
Array.Sort(array, (first, second) =>
string.Compare(first[2], second[2]));
来源:https://stackoverflow.com/questions/19526086/sorting-a-jagged-array-by-second-column