C# : Overriding Equality for Reference Types

Procedure for implementing equality for Reference Types:

  • Override object.Equals()
  • Override object.GetHashCode()
  • Implement == and != overloads

NOTE

  • IEquatable is only appropriate for sealed types : Due to inheritance. You may not be using the overloaded .Equals method and the compiler will not understand how to check for equality if you are using the base class Equal method.

  • Equality logic should go in the object.Equals method when overriding.