11

I've read this post but it doesn't answer my question.

MSDN says:

We recommend that you derive from the EqualityComparer(Of T) class instead of implementing the IEqualityComparer(Of T) interface, because the EqualityComparer(Of T) class tests for equality using the IEquatable(Of T).Equals method instead of the Object.Equals method.

but if I look at the implementation, they both use the generic Type:

 public class AAA:IEqualityComparer<Box>
    {
        public bool Equals(Box x, Box y)
        {
        }

        public int GetHashCode(Box obj)
        {
        }
    }

    public class BBB : EqualityComparer<Box>
    {
        public override bool Equals(Box x, Box y)
        {
        }

        public override int GetHashCode(Box obj)
        {
        }
    }

What am I missing?

Community
  • 1
  • 1
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
  • 3
    No idea. That statement makes no sense to me. – CodesInChaos Mar 04 '12 at 21:21
  • The answers to the other question already explained that this statement makes no sense. So I don't get what you're expecting out of this question. – CodesInChaos Mar 04 '12 at 21:28
  • 4
    possible duplicate of [Preferring EqualityComparer to IEqualityComparer](http://stackoverflow.com/questions/5707347/preferring-equalitycomparert-to-iequalitycomparert) – CodesInChaos Mar 04 '12 at 21:29
  • @CodeInChaos did you read the answers there? none of them was a strict answer ... The accepted answer gave explanation about the Compare interface and assumed it might be relevant to Equality....jOn skeet didnt know about his first question either. so your duplicate vote is from not-reading.\ – Royi Namir Mar 04 '12 at 21:36
  • 7
    I read those answers as "the statement is bullshit and makes no sense", except they're too polite to say it in such an explicit way. While MSDN is a valuable resource, don't take everything MSDN says as gospel. MSDN contains plenty of bad advice, outdated, badly written or plain wrong content. – CodesInChaos Mar 04 '12 at 22:07
  • @RoyiNamir, EqualityComparer has the implementation for both generic and non-generic version of the IEqualityComparer. Thats the only difference I can see. – Karthik D V Feb 16 '15 at 19:26

1 Answers1

4

I think the other post you mention is saying that EqualityComparer<Box> implements IEqualityComparer<Box> and IEqualityComparer, so you don't have to implement both the generic and non-generic interfaces if you derive from EqualityComparer<Box>.

Community
  • 1
  • 1
phatraven
  • 66
  • 2
  • 6