Sorting a jagged array by second column

跟風遠走 提交于 2021-02-04 07:38:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!