Skip to content

Instantly share code, notes, and snippets.

@thinktainer
Created March 20, 2013 13:45
Show Gist options
  • Save thinktainer/5204735 to your computer and use it in GitHub Desktop.
Save thinktainer/5204735 to your computer and use it in GitHub Desktop.
Efficient hasher
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hash = 17;
// Suitable nullity checks etc, of course :)
hash = hash * 23 + field1.GetHashCode();
hash = hash * 23 + field2.GetHashCode();
hash = hash * 23 + field3.GetHashCode();
return hash;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment