【问题标题】:Array of HashSets with comparer in C#C# 中带有比较器的 HashSet 数组
【发布时间】:2016-01-04 10:31:45
【问题描述】:

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

//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# arrays hashset icomparer


    【解决方案1】:

    你有一个HashSet&lt;T&gt;的数组,你需要初始化数组中的每个元素:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-04
      • 2010-10-17
      • 1970-01-01
      • 2011-08-14
      • 2019-01-13
      • 1970-01-01
      相关资源
      最近更新 更多