Using GetHashCode for getting Enum int value

Using GetHashCode() is incorrect. You should cast to int. Using it the way you do is asking for raptors(or Raymond) to come and eat you. That GetHashCode() happens to return the integer value of the enum is an implementation detail and may change in future versions of .net. GetHashCode() guarantees that if two values are … Read more

General advice and guidelines on how to properly override object.GetHashCode()

Table of contents When do I override object.GetHashCode? Why do I have to override object.GetHashCode()? What are those magic numbers seen in GetHashCode implementations? Things that I would like to be covered, but haven’t been yet: How to create the integer (How to “convert” an object into an int wasn’t very obvious to me anyways). … Read more

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