少なくとも 1 つのフィールドが一致するGetHashCode
場合にオブジェクトが等しいと見なされる場合、関数をオーバーライドする最良の方法は何でしょうか。
ジェネリックEquals
メソッドの場合、例は次のようになります。
public bool Equals(Whatever other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
// Considering that the values can't be 'null' here.
return other.Id.Equals(Id) || Equals(other.Money, Money) ||
Equals(other.Code, Code);
}
GetHashCode
それでも、この場合の適切な実装を行うことについて混乱しています。
これはどのように行うべきですか?
ありがとうございました。