更新时间: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.