Maintaining equality with the inheritance hierarchy is complex. You need to pinpoint what you mean. Do you really need inheritance here? If not, if Point2 comes directly from System.Object, and you can make it sealed, life will be a little easier. In this case, I would use:
public override bool Equals (object obj)
{
return Equals(obj as Point2);
}
public bool Equals (Point2 obj)
{
if (object.ReferenceEquals(obj, null))
{
return false;
}
if (object.ReferenceEquals( this, obj))
{
return true;
}
return this.X == obj.X && this.Y == obj.Y;
}
source
share