views:

64

answers:

1

I have a HashSet with it's own EqualityComparer, but I am wondering if a simple count of both sets is used before checking each element?

I thought I would be able to answer this for myself in Reflector but I couldn't find any override of Equals in there.

Cheers,
Berryl

EDIT ==========

As Hans noted, it it the comparison of two sets that I am interested in, as part of an override of Equals in a class that has a HashSet as a property?

+3  A: 

You are mixing it up. Implementing your own IEqualityComparer<> is useful to compare the elements you put in the HashSet. The Count property would only ever be useful if you want to compare the sets. Two very different things. There is no default implementation of Equals(). The HashSet.SetEquals() method indeed first checks the Count properties, if possible.

Hans Passant
@Hans. perfect, this is what I was looking for. Cheers
Berryl