我正在寻找一种从锯齿状数组中获取不同值的方法。我试过把它放在字典里,但它似乎并没有看到这些值是不同的。任何人对解决方案有任何想法吗?这是我到目前为止所拥有的:
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]
有什么想法我怎么能做到这一点?