Is there a complete IEquatable implementation reference?

Implementing IEquatable<T> for a Value Type Implementing IEquatable<T> for a value type is a little bit different than for a reference type. Let’s assume we have the Implement-Your-Own-Value-Type archetype, a Complex number struct. public struct Complex { public double RealPart { get; set; } public double ImaginaryPart { get; set; } } Our first step … Read more

What’s the difference between IEquatable and just overriding Object.Equals()?

The main reason is performance. When generics were introduced in .NET 2.0 they were able to add a bunch of neat classes such as List<T>, Dictionary<K,V>, HashSet<T>, etc. These structures make heavy use of GetHashCode and Equals. But for value types this required boxing. IEquatable<T> lets a structure implement a strongly typed Equals method so … Read more