The GetHashCode
method always returns a 32 bit int
, no matter what type or system you call it on. Thats the point of it and I don't see anything forcefully there. After all, there is no problem with using any object or struct of any size as key. (If they have a somewhat useful implementation of GetHashCode
.)
The dictionary will probably end up with some collisions, but as long as the hash codes are distributed evenly across the 32 bit range thats fine.
Edit
So yes, the dictionary always calls the GetHashCode
method, even for int
, where it's rather simple:
public override int GetHashCode()
{
return this;
}
For long
(int64
) it looks like this:
public override int GetHashCode()
{
return (int) this ^ (int) (this >> 32);
}