What is “Best Practice” For Comparing Two Instances of a Reference Type?
Implementing equality in .NET correctly, efficiently and without code duplication is hard. Specifically, for reference types with value semantics (i.e. immutable types that treat equvialence as equality), you should implement the System.IEquatable<T> interface, and you should implement all the different operations (Equals, GetHashCode and ==, !=). As an example, here’s a class implementing value equality: … Read more