二维数组问题
我定义一个二维数组 int[,] ary = new int[4, 2] { { 1, 2 }, { 5, 6 }, { 9, 0 }, { 1, 3 } };我想把第一列相同的放在一个数组里
比如:
{1,2}和{1,3}放在一起
其他的不想同的从新建个数组 存起来 就是循环相同的放一起
求大神如何实现 --------------------编程问答-------------------- 你想得到多个第一列相同的数组吗? --------------------编程问答-------------------- 嗯 把相同的放在一个数组里 --------------------编程问答--------------------
嗯 把相同的放在一个数组里 --------------------编程问答--------------------
--------------------编程问答--------------------
//int[,] ary = new int[,] { { 1, 2 }, { 5, 6 }, { 9, 0 }, { 1, 3 } };
List<int[]> ary = new List<int[]>();
ary.Add(new int[] { 1, 2 });
ary.Add(new int[] { 5, 6 });
ary.Add(new int[] { 9, 0 });
ary.Add(new int[] { 1, 3 });
List<List<int[]>> lary = new List<List<int[]>>();
foreach (int[] lv in ary)
{
bool flag = false;
foreach (List<int[]> av in lary)
{
if (av.FirstOrDefault()[0] == lv[0])
{
av.Add(lv);
flag = true;
}
}
if (!flag)
{
List<int[]> temp = new List<int[]>();
temp.Add(lv);
lary.Add(temp);
}
}
补充:.NET技术 , C#