.NET C# - 数组中不同数组的数量

Dan*_*nny 3 c# 2d permutation distinct multidimensional-array

我是新来的,对 C# 有点缺乏经验。我一直在 MSDN 文档和 Google 中搜索,但找不到答案(我尝试尽可能笼统地表述):

我想在列表或数组中存储固定长度的有序整数序列,然后创建这些整数数组的数组。有谁知道如何计算不同整数数组的数量,以及应该使用哪些特定数据类型(列表、普通数组等)?我没有我一直在使用的确切代码,但这里有一些与我一直在尝试的类似的代码:

int[] set1 = {2, 56, 8};
int[] set2 = {8, 25, 90};
int[] set3 = {2, 56, 8};

var superset = new List<int[]>;
superset.Add(set1);
superset.Add(set2);
superset.Add(set3);

Console.Out.WriteLine(superset.Distinct().Count());  //  would like this to output 2, but Distinct() doesn't seem to actually work and I would get 3
Run Code Online (Sandbox Code Playgroud)

Bob*_*Bob 5

该方法有一个重载,它采用IEqualityComparerDistinct的实例。为 int 数组(即)创建 IEqualityComparer 的实现,并将一个实例传递到对 Distinct 的调用中。public class IntArrayComparer : IEqualityComparer<int[]>

SequenceEqual方法可能对实现有一些帮助IEqualityComparer<int[]>.Equals但该练习留给您。