Question

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?

Was it helpful?

Solution

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>.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top