title: When Implementing IEqualityComparer Should GetHashCode check for null?
body: <p>When implementing <code>IEqualityComparer&lt;Product&gt;</code> (<code>Product</code> is a class), ReSharper complains that the null check below is always false:</p>
  
  <pre><code>public int GetHashCode(Product product)
  {
    // Check whether the object is null. 
    if (Object.ReferenceEquals(product, null))
      return 0;
  
    // ... other stuff ...
  }
  </code></pre>
  
  <p>(Code example from <a href="http://msdn.microsoft.com/en-us/library/bb336390%28v=vs.90%29.aspx" rel="noreferrer">MSDN VS.9 documentation of Enumerable.Except</a>)</p>
  
  <p>ReSharper may be wrong, but when searching for an answer, I came across the <a href="http://msdn.microsoft.com/en-us/library/ms132151%28v=vs.110%29.aspx" rel="noreferrer">official documentation for <code>IEqualityComparer&lt;T&gt;</code></a> which has an example where null is not checked for:</p>
  
  <pre><code>public int GetHashCode(Box bx)
  {
      int hCode = bx.Height ^ bx.Length ^ bx.Width;
      return hCode.GetHashCode();
  }
  </code></pre>
  
  <p>Additionally, the documentation for <a href="http://msdn.microsoft.com/en-us/library/ms132155%28v=vs.110%29.aspx" rel="noreferrer"><code>GetHashCode()</code> states</a> that <code>ArgumentNullException</code> will be thrown when "The type of obj is a reference type and obj is null."</p>
  
  <p>So, when implementing <code>IEqualityComparer</code> should <code>GetHashCode</code> check for null, and if so, what should it do with null (throw an exception or return a value)?</p>
  
  <p>I'm interested most in .NET framework official documentation that specifies one way or another if null should be checked.</p>