Implementing Equality Operations
One of the most commonly overloaded operators is ==
(and its !=
sister operator). To ensure expected behavior for those operators, a few guidelines exist. In particular, we have to explain the relationship between the operators and the System.Object Equals
methods that are available.
The Role of System.Object
’s Instance
Equals Method
Defined on System.Object
, the “mother type of all types”, the Equals
instance method is used to compare whether two objects are “equal,” whatever that means for the types of the target object and the one being compared.
As you learn in Chapter 14, “Object-Oriented Programming,” virtual ...
Get C# 4.0 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.