的情況下,我有以下情況其中的GetHashCode將主導的IComparer
class Custom
{
public override int GetHashCode(){...calculation1}
}
public class MyComparer : IEqualityComparer<Custom>
{
public bool Equals(Custom cus1, Custom cus2)
{
if (cus1 == null || cus2 == null)
return false;
return cus1.GetHashCode() == cus2.GetHashCode();
}
public int GetHashCode(Custom cus1)
{
return ...calculation2;
}
}
int Main()
{
List<Custom> mine1 = new List<Custom>(){....};
List<Custom> mine2 = new List<Custom>(){....};
MyComparer myComparer = new MyComparer();
List<Custom> result = mine1.intersect(mine2,myComparer);
}
這裏只是我想知道的GetHashCode將在交叉使用。
'return cus1.GetHashCode()== cus2.GetHashCode();'這是一個可怕的平等觀念。在我看來,你的散列函數沒有正確設計速度。 – leppie