按第二列对锯齿状数组进行排序 [英] Sorting a jagged array by second column

查看:73
本文介绍了按第二列对锯齿状数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个锯齿状的数组,我需要按"2"列对其进行排序:

I have a jagged array and I need to sort it by the column "2":

示例:array [x] [2]

example: array[x][2]

我大约有64个"x",第二列("2"是),我有4个不同的选项,但是我需要按第二个选项进行排序.

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.

推荐答案

只需使用 OrderBy :

array = array.OrderBy(inner => inner[2]).ToArray();

如果使用就地排序很重要,则可以使用 Array.Sort :

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]));

这篇关于按第二列对锯齿状数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆