I saw this hash function - and it triggered some alarms:
public override int GetHashCode()
{
var result = 0;
unchecked {
result = anIntId.GetHashCode();
result *= 397 * (aString != null ? aString.GetHashCode() : 0);
}
return result;
}
my automated hash-code-smell-fixer-subroutine wants to rewrite it to read:
public override int GetHashCode()
{
var result = 0;
unchecked {
result = anIntId.GetHashCode() * 397;
result = (result * 397) ^ (aString != null ? aString.GetHashCode() : 0);
}
return result;
}
i can't remember where i learned this pattern, but it seems that some of it doesn't actually make sense:
- the first multiplication by 397 looks like a waste of time
- [redacted] {in brain minus coffee context, interpreted ^ to be exponentiation}
does this seem correct, or am i making some mistakes?