我正在寻找一种方法从锯齿阵列中获取不同的值。我试图把它放在字典中,但它似乎并没有看到这些值是不同的。任何人有任何解决方案的想法?以下是我迄今为止:C#从锯齿阵列中获取不同的值
int[][] connectionList = GetArray();
数据采样从这个返回:
[0][1, 130, 136, 138]
[1][1, 78, 126, 138]
[2][1, 10, 125, 138]
[3][1, 130, 136, 138]
[4][1, 78, 126, 138]
[5][1, 130, 136, 138]
[6][1, 72, 135, 138]
[7][1, 73, 135, 138]
[8][1, 130, 136, 138]
试过加入字典。我试图为它们加入到追赶重复值,但没有工作,那么尝试添加.Distinct(),但没有喜悦有任何
Dictionary<int, int[]> myDictionary = new Dictionary<int, int[]>();
for (int i = 0; i < connectionList.Length; i++)
{
List<int> list = new List<int>();
for (int j = 0; j < connectionList[i].Length; j++)
{
list.Add(connectionList[i][j]);
}
if (myDictionary.Where(x => x.Value == list.ToArray()).Count() == 0)
myDictionary.Add(i, list.ToArray());
}
var distinctList = myDictionary.Values.Distinct().ToList();
从上面的列表,输出我期待因为将是:
[0][1, 130, 136, 138]
[1][1, 78, 126, 138]
[2][1, 10, 125, 138]
[4][1, 72, 135, 138]
[5][1, 73, 135, 138]
任何想法,我怎么能实现这一点?
它应该是唯一的每个关键或全球? – user7116 2012-01-30 16:17:56
预期产量是多少? – cadrell0 2012-01-30 16:19:43
只有价值需要是唯一的 - 关键不重要。 – 2012-01-30 16:21:39