This question already has an answer here:
- What is the best algorithm for an overridden System.Object.GetHashCode? 19 answers
I have a struct that overrides the Equals()
method and the compiler complains about GetHashCode()
not being overridden.
My struct:
private struct Key
{
...
public override int GetHashCode()
{
return ?;
}
public int FolderID;
public MyEnum SubItemKind;
public int SubItemID;
}
What is the right way to implement the GetHashCode()
method?
a)
return FolderID ^ SubItemKind.GetHashCode() ^ SubItemID;
or b)
return FolderID.GetHashCode() ^ SubItemKind.GetHashCode() ^ SubItemID.GetHashCode();