何时在面向 .NET 4.0 的应用中使用 IEqualityComparer
实施弱类型 IEqualityComparer 对我有什么好处.NET 4.0 应用程序中的
除了 IEqualityComparer
接口?
另一个角度是,我始终可以实现 IEqualityComparerIEqualityComparer
来获取新代码。
Is there any benefit for me to implement the weakly typed IEqualityComparer
in .NET 4.0 apps in addition to the IEqualityComparer<T>
interface?
Another angle is I can always implement IEqualityComparer<System.Object>
to make up an equally weakly typed scenario and never need to resort to IEqualityComparer
for new code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只是从
EqualityComparer
那么您不必担心它,因为它同时实现了IEqualityComparer
和IEqualityComparer
。因此,当您实现强类型时,您可以免费获得弱类型。也就是说,您不太可能发现自己需要弱类型版本。只有少数 BCL 类使用它,而且它们并不常见。
If you just derive from
EqualityComparer<T>
then you don't have to worry about it because it implements bothIEqualityComparer
andIEqualityComparer<T>
. So you get weak typing for free when you implement strong typing.That said, it's reasonably unlikely that you'll find yourself needing the weakly-typed version. Only a handful of BCL classes use it, and they're not common ones.