wpf 重写 ContentControl 中的 getHashCode 和 Eqaul

发布于 2024-09-26 17:41:31 字数 222 浏览 0 评论 0原文

你好 我有一个派生自 ContentControl 的类,我无法重写 GetHashCode 和 Equal 方法。我收到错误

错误 5 无法覆盖继承成员“System.Windows.DependencyObject.GetHashCode()”,因为它是密封的 有什么办法可以重写这个方法吗? 我需要使用 LINQ 中的 Union 方法,但是我需要比较具有与正常条件不同的条件的对象。有什么办法可以做到吗?

Hi
I have a class which derives from ContentControl and I'm not able to override GetHashCode and Equal method. I get an error

Error 5 cannot override inherited member 'System.Windows.DependencyObject.GetHashCode()' because it is sealed
Is there any way to override this method ?
I need to use Union method from LINQ however I need to compare object with different condition than normal. Is there any way to do it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁〃客ぐ 2024-10-03 17:41:31

是 - 单独实施 IEqualityComparer,并将其传递到 Union 的相关重载。

基本上,您将告诉它如何比较任意两项的相等性,以及如何获取任意一项的哈希码。 Union 将在构建哈希集等时使用您的自定义比较。您不需要覆盖任何现有方法。

Yes - implement IEqualityComparer<T> separately, and pass that into the relevant overload of Union.

Basically you'll be telling it how to compare any two items for equality, and how to take the hash code of any one item. Union will use your custom comparison when building up hash sets etc. You don't need to override any existing methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文