Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array of HashSets with comparer in C#

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

like image 824
Yann Avatar asked Jan 04 '16 10:01

Yann


1 Answers

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());
}
like image 104
Yuval Itzchakov Avatar answered Sep 23 '22 13:09

Yuval Itzchakov