Skip to content

Instantly share code, notes, and snippets.

@jjvdangelo
Created July 13, 2013 23:44
Show Gist options
  • Save jjvdangelo/5992614 to your computer and use it in GitHub Desktop.
Save jjvdangelo/5992614 to your computer and use it in GitHub Desktop.
A simple helper for implementing GetHashCode().
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