HashSets array with comparator in C #

as the title says, I have an array of hash sets, but I don't know how to apply a comparator to them. 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 a compactor. What am I doing wrong? thank you

+4
source share
1 answer

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

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

Source: https://habr.com/ru/post/1622716/


All Articles