It depends very much on how your data is typically different from each other.
You may write this hash code function:
return arr.Length;
And it could perfectly fit if most of your arrays have a different size.
Or you may use the first two items if your array has typically completely different content.
Note: it doesn't make sense to loop the whole array and do something more complex than comparing to the value of another array. Why? Because the hash code is used for performance optimization only. So it should be way quicker than Equals
. And Equals
compares all the values.
When the arrays are different in size, Equals
wouldnt't loop. Instead it returns immediately after comparing Length
. Try to beat this in the hash code function.