Equality relates to the values of the fields: Are two variables pointing to objects that have the same values in their fields? For example, two account objects might be equivalent if the objects have the same account number and the same balance. Why is this necessary? Suppose you have an array of Person objects. Each Person has a name and an age. If you want to search the array for a particular person, the system has to know what values to use for the comparison. There is no way the system can test arbitrary fields for comparison. Instead, the .NET framework lets you define what equality means yourself. This is done by overriding two methods from the class System.Object: Equals() and GetHashCode() . To override the Equals and GetHashCode functions:
Tip
|