I'm trying to do the hashing the right way (I admit that I usually can be a bit sloppy there, relying on the automagical management). I think I got it under control but I feel uncertain if it's really the fully correct approach or if I'm missing something (yes, I've read quite a few pages on it but still...).
In my class, I have designed something like this. I'm leaving out the definition of Segment
intentionally, because I believe that my approach is correct without knowing it.
public class Compound
{
public Segment PartA { get; set; }
public Segment PartB { get; set; }
...
public int GetHashCode()
{
return PartA.GetHashCode() * PartB.GetHashCode()
}
}
The method seems to be safe, as the integers won't overflow but instead wrap around the maximum. The advantage of this approach is to me that both parts will actually affect the hash produced.
I wonder though if I should be using multiplication or addition (or something totally else) when computing it. Do I actually gain anything from hashing in both of the parts? I can't really tell.