title: Creating the GetHashCode method in C#
body: <p>What is the best way to create your own GetHashCode method for a class in C#?  Suppose I have a simple class (which overrides the Equals method), as follows:</p>
  
  <pre><code>class Test
  {
     public string[] names;
  
     public double[] values;
  
     public override bool Equals(object obj)
     {
        return (obj is Test) &amp;&amp; this.Equals((Test)obj);
     }
  
     public bool Equals(Test t)
     {
        return names.Equals(t.names) &amp;&amp; values.Equals(t.values);
     }
  }
  </code></pre>
  
  <p>Should I use the default code for the GetHashCode method?</p>
  
  <pre><code>public override int GetHashCode()
  {
     return base.GetHashCode();
  }
  </code></pre>
  
  <p>Should I base the method on the contents of my class?</p>
  
  <pre><code>public override int GetHashCode()
  {
     return names.GetHashCode() + values.GetHashCode() ;
  }
  </code></pre>
  
  <p>Or should I do something else?</p>