2016-01-04 30 views
4

如標題所示,我有一個哈希集數組,但我不知道如何將它們應用於比較器。像這樣:在C#中使用比較器的哈希集合數組#

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

當然,我需要比較器..我做錯了什麼? 謝謝

回答

4

你有HashSet<T>數組,所以你需要初始化數組中的每個元素:

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