我试图将两个数组相互比较.我试过这段代码并得到以下错误.
static bool ArraysEqual(Array a1, Array a2)
{
if (a1 == a2)
return true;
if (a1 == null || a2 == null)
return false;
if (a1.Length != a2.Length)
return false;
IList list1 = a1, list2 = a2; //error CS0305: Using the generic type 'System.Collections.Generic.IList<T>' requires '1' type arguments
for (int i = 0; i < a1.Length; i++)
{
if (!Object.Equals(list1[i], list2[i])) //error CS0021: Cannot apply indexing with [] to an expression of type 'IList'(x2)
return false;
}
return true;
} …
Run Code Online (Sandbox Code Playgroud) 我有一个类,内部只是一个整数数组.一旦构造,阵列永远不会改变.我想预先计算一个好的哈希码,以便这个类可以非常有效地用作词典中的键.数组的长度小于约30项,并且整数通常在-1000和1000之间.
geneUsingCrossover是一个List<List<double>>
.
我使用下面的代码行数的独特List<double>
之内List<List<double>>
:
int count = genesUsingCrossover.Distinct().Count();
Run Code Online (Sandbox Code Playgroud)
而且我不确定它是否正确.元素的数量genesUsingCrossover
是1250,也genesUsingCrossover.Distinct().Count()
返回1250,所以我假设它们都是不同的List.但是,在观察窗口中,我注意到第三和第四个列表是相同的.
所以,我认为代码行不正确.有没有办法改善它?并计算不同元素的数量?