楼主是要这样的吗? var arry = new Array[] { new string[] { "a", "b" }, new string[] { "x", "y" }, new string[] { "a", "c" }, new string[] { "a", "b" }, new string[] { "x", "b" } }; //查找第一个是"a"的所有数组的第二个值 var second = arry.Where(x => x.GetValue(0).ToString() == "a").Select(x=>x.GetValue(1)).ToList();
或者这样,如果数组是int型的,改成int型就可以了 var arry = new Array[] { new string[] { "a", "b" }, new string[] { "x", "y" }, new string[] { "a", "c" }, new string[] { "a", "b" }, new string[] { "x", "b" } }; //查找第一个是"a"的所有数组的第二个值 var second = (from q in arry where q.GetValue(0).ToString() == "a" select q.GetValue(1)).ToList();
var arry = new Array[] { new string[] { "a", "b" }, new string[] { "x", "y" }, new string[] { "a", "c" }, new string[] { "a", "b" }, new string[] { "x", "b" } };
//查找第一个是"a"的所有数组的第二个值
var second = arry.Where(x => x.GetValue(0).ToString() == "a").Select(x=>x.GetValue(1)).ToList();
//查找第一个是"a"的所有数组的第二个值
var second = (from q in arry
where q.GetValue(0).ToString() == "a"
select q.GetValue(1)).ToList();
我用数组排序解决了。
我将第一个数组成一个数组arr,第二个数组成一个数组another,因为我第一个数是数字的我转换成int比较了。这样我第一个数组对应的index,从第二个数组该index读出的就是对应的值。
private string[] sortArr(string[] arr,string[] another)
{
for (int i = 0; i < arr.Length; i++)
{
for (int j = i; j < arr.Length; j++)
{
if (int.Parse(arr[i]) > int.Parse(arr[j]))
{
//string temp = arr[i];
//arr[i] = arr[j];
//arr[j] = temp;
string anotherTemp = another[i];
another[i] = another[j];
another[j] = anotherTemp;
}
}
}
return another;
}