且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

LINQ和放大器;层次分明,实现equals和放大器; gethash code

更新时间:2021-10-04 01:34:51

您需要重写等于(对象)方法:

public override bool Equals(object obj) {
    return Equals(obj as parent);
}

的Object.Equals 办法(不像 EqualityComparer< T> .DEFAULT )不使用 IEquatable 接口。因此,当你写的Object.Equals(C1,other.c1),它不会打电话给你的 Child.Equals(儿童)方法。

The object.Equals method (unlike EqualityComparer<T>.Default) does not use the IEquatable interface. Therefore, when you write object.Equals(c1, other.c1), it doesn't call your Child.Equals(Child) method.

您没有绝对需要做的为好,但您真的应该的。

You don't absolutely need to do that for parent as well, but you really should.