4

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.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
John K
  • 28,441
  • 31
  • 139
  • 229

1 Answers1

4

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.

Gabe
  • 84,912
  • 12
  • 139
  • 238