开发者

When to use IEqualityComparer in an app targeting .NET 4.0

Is there any benef开发者_高级运维it 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.


If you just derive from EqualityComparer<T> then you don't have to worry about it because it implements both IEqualityComparer and IEqualityComparer<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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜