Short question
How to implement GetHashCode
for an Array
.
Details
I have an object that overrides Equals
, checking that:
this.array[n] == otherObject.array[n]
for all n
in array
.
Naturally I should implement the complementary GetHashCode
.
I was wondering if there is .NET way to do this, or if I should implement my own, something like
hash = hash ^ array[n]
Clarification
My object contains an array, and I'm interested on GetHashCode for the elements of the array. My code for array equivalence is for example only - like my question says but maybe I wasn't clear, I'm interested in GetHashCode
(not Equals
). I say I naturally should implement the complementary GetHashCode
because it is a requirement of .NET to implement this once Equals
is overridden (for Dictionary
etc. to function correctly). Thanks.