c# - C# 中带比较器的 HashSet 数组

标签 c# arrays hashset icomparer

正如标题所说,我有一个哈希集数组,但我不知道如何将比较器应用于它们。像这样:

//This Works:
public HashSet<Animal.AnimalCell>UpdateList = new HashSet<Animal.AnimalCell>(new CellComparer());
//This Does not work: 
public HashSet<Animal.AnimalCell>[]UpdateListThreaded = new HashSet<Animal.AnimalCell>(new CellComparer())[10];
//This Does not Work :
public HashSet<Animal.AnimalCell>[]UpdateListThreaded = new HashSet<Animal.AnimalCell>[10](new CellComparer());
//This Works:
public HashSet<Animal.AnimalCell>[]UpdateListThreaded = new HashSet<Animal.AnimalCell>[10];

当然我需要比较器..我做错了什么? 谢谢

最佳答案

你有一个 HashSet<T> 的数组,你需要初始化数组中的每个元素:

for (int i = 0; i < UpdateList.Length; i++)
{
    UpdateList[i] = new HashSet<AnimalCell>(new CellComparer());
}

关于c# - C# 中带比较器的 HashSet 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34589126/

相关文章:

C# SQL Connection string "can' t 查找表"

c - 简单的 C 程序,未知的输出

C 编程创建动态数组

java - HashSet 正在排序

c# - Windows Phone 7 测试的最佳模拟库

c# - Unity 销毁 GameObject 实例化克隆

java - 将对象添加到 HashSet

c# - 复杂类型的 HashSet 中的 ExceptWith

c# - 如何为 out 参数指定 Ensures?

Javascript 事件增量索引