Sorry to combine two questions into one, they are related.
HashCode
s for HashSet
s and the such. As I understand it, they must be unique, not change, and represent any configuration of an object as a single number.
My first question is that for my object, containing the two Int16s a
and b
, is it safe for my GetHashCode
to return something like a * n + b
where n is a large number, I think perhaps Math.Pow(2, 16)
?
Also GetHashCode
appears to inflexibly return specifically the type Int32.
32bits can just about store, for example, two Int16s, a single unicode character or 16 N, S, E, W compass directions, it's not much, even something like a small few node graph would probably be too much for it. Does this represent a limit of C# Hash collections?