Out of interest how does the GetHashCode of a concrete implementation of IEqualityComparer work?
The reason that I ask is that I'm using linq to union two collections, and when only the left collection has an item GetHashCode is called twice. Further to that, it's called four times if both collections have one row.
This is rough typing but you'll get the point. GetHashCode is called twice, which I'm guessing is twice for the one item in listOne?
e.g.
var listOne = new List<SearchResult>{new SearchResult{Name="Blah"}};
var listTwo = new List<SearchResult>();
listOne.Union(listTwo, SearchResultComparer);
public class SearchResultComparer : IEqualityComparer<SearchResult>
{
public bool Equals(SearchResult x, SearchResult y){....}
public int GetHashCode(SearchResult obj)
{
unchecked
{
int result = 0;
result = (result * 397) ^ (obj.Name != null ?
return result;
}
}
}
Thanks