Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 29
    Well, it will cause boxing, if fields are value types. Commented Apr 4, 2010 at 15:39
  • 7
    "can be enhanced later by catching the OverflowException" The whole point of the unchecked is to avoid exceptions on overflow which is desired on GetHashCode. So it's not incorrect if the value overflows int and it does not hurt at all. Commented Feb 24, 2014 at 13:06
  • 2
    One issue with this algorithm is that any array full of nulls will always return 0, regardless of it's length Commented Apr 17, 2015 at 12:12
  • 3
    This helper method also allocates a new object[] Commented Jul 20, 2016 at 12:35
  • 2
    As @NathanAdams mentions, the fact that null is skipped entirely could give you unexpected results. Instead of skipping them, you should just use some constant value instead of input[i].GetHashCode() when input[i] is null. Commented Oct 28, 2016 at 19:04