One of my C# books (C# 3.0 Cookbook by Hillyard and Teilhet) in giving an example of a Square class writes the GetHashCode as
public override int GetHashCode ( )
{
return this.Height.GetHashCode() | this.Width.GetHashCode();
}
I'm wondering why this is considered a good hash code. Becuase the table for an | operation is
x | y | x OR y
--------------
0 | 0 | 0
1 | 0 | 1
0 | 1 | 1
1 | 1 | 1
which means that 3/4 of the time the result of the operation is 1. So if you have miscellaneous ints w, x, y, z that means the chance that w | x == y | z is not as small as it could be (if ^ was used, for example).
Is my understanding of this corret? Or is there a good reason why | is used for the hashing function?