5

as the title says, i have an array of hashsets, but i don't know how apply to them a comparer. Like this:

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

Of Course i need the comparer.. What am i doing wrong? Thank you

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
Yann
  • 180
  • 3
  • 14

1 Answers1

5

You have an array of HashSet<T>, you need to initialize each element in the array:

for (int i = 0; i < UpdateList.Length; i++)
{
    UpdateList[i] = new HashSet<AnimalCell>(new CellComparer());
}
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321