I've been looking all over the place, but I can't find anything. Can anyone shed some light on this?
+6
A:
According to Reflector:
public override int GetHashCode()
{
return this;
}
Makes sense, does it?
Michael Stum
2010-10-08 19:41:24
I suppose. I was thinking all value types would have a common implementation.
Esteban Araya
2010-10-08 19:43:15
No, each Value type has it's own. UInt32 casts itself to Int32, this simply turning itself to a Signed Int. Int16 and Int64 do some funky bit shifting to generate a 32-Bit Value. System.Boolean returns 0 or 1 depending on it's state.
Michael Stum
2010-10-08 19:46:43
A:
Best way to hash 32 bit value to 32 bit is not to invent wheel, use value itself. Very fast, no collisions, indeed a perfect way.
Daniel Mošmondor
2010-10-08 19:43:11
Yes, but that doesn't necessarily mean it was implemented that way. :)
Esteban Araya
2010-10-08 19:47:11