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.
精彩评论