Created
July 13, 2013 23:44
-
-
Save jjvdangelo/5992614 to your computer and use it in GitHub Desktop.
A simple helper for implementing GetHashCode().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Helpers | |
{ | |
// Used like: | |
// public override int GetHashCode() { | |
// return 17.CombineHashWith(foo).CombineHashWith(bar).CombineHashWith(GetType()); | |
// } | |
public static int CombineHashWith<T>(this int initialHash, T other) | |
{ | |
var otherHash = other == null ? 0 : other.GetHashCode(); | |
return initialHash + initialHash * 23 + otherHash; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment