CHAPTER 6 UNDERSTANDING INHERITANCE AND POLYMORPHISM
}
}
}
return false;
Here, you are examining the values of the incoming object against the values of your internal values
(note the use of the this keyword). If the name and age of each are identical, you have two objects with
the exact same state data and, therefore, return true. Any other possibility results in returning false.
While this approach does indeed work, you can certainly imagine how labor intensive it would be to
implement a custom Equals() method for nontrivial types that may contain dozens of data fields. One
common shortcut is to leverage your own implementation of ToString(). If a class has a prim-andproper implementation of ToString() that accounts for all field data up the chain of inheritance, you can
simply perform a comparison of the object’s string data:
public override bool Equals(object obj)
{
//