Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个带有自己的 EqualityComparer 的 HashSet,但我想知道在检查每个元素之前是否使用了两个集合的简单计数?
我以为我可以在 Reflector 中为自己回答这个问题,但我在那里找不到任何对 Equals 的覆盖。
干杯, 贝里尔
编辑 ==========
正如汉斯所指出的,它是我感兴趣的两个集合的比较,作为在具有 HashSet 作为属性的类中覆盖 Equals 的一部分?
你把它弄混了。实现您自己的 IEqualityComparer<> 对于比较您放入 HashSet 中的元素很有用。Count 属性只有在您想比较集合时才有用。两种截然不同的东西。Equals() 没有默认实现。如果可能,HashSet.SetEquals() 方法确实首先检查 Count 属性。