C#中带有比较器的哈希集数组

本文关键字:哈希集 数组 比较器 | 更新日期: 2023-09-27 18:29:02

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

//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];

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

C#中带有比较器的哈希集数组

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

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