title: GetHashCode With Generic Collection Returns Different Values
body: <p>It looks like hash code issues and implementing your own equality logic have been beaten to death, but I cannot seem to find a definitive answer to this.</p>
  
  <p>I have a custom object (Step) that overrides Equals, GetHashCode, ==, and != as suggested by the <a href="https://msdn.microsoft.com/ru-ru/library/ms173147(v=vs.80).aspx" rel="nofollow noreferrer">MSDN documentation</a>.  This object by itself works fine; When comparing a Step to a Step, the equality operators work as expected.  Note that by equality I'm referring to the values of the Step's properties, not reference equality.</p>
  
  <p>I have a second object (Steps) that stores the Step object in a generic list.  Now I want to see if a list of Step objects is equal to another list of Step objects.  In the Steps object I overrode the various methods and operators as I had done in Step.  For the GetHashCode override, I iterate through the Step list and combine the hash codes:</p>
  
  <pre><code>foreach(var step in steplist.Steps)
  {
      hash += step.GetHashCode()
  }
  return hash
  </code></pre>
  
  <p>Simple.  But it does not work.  The hash codes for two separate lists with equal Step objects values return different hash codes.  I'm assuming I'm not implementing the hash code override correctly.</p>
  
  <p>I'm about ready to hard code the returning hash code to zero and call it a day.  Any insight is appreciated.</p>
  
  <p>Edit:</p>
  
  <p>Sorry, I was trying to be brief so as to avoid a wall of text.  Here is the hash code generation for the Step object.   Taken from <a href="https://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-an-overridden-system-object-gethashcode">What is the best algorithm for an overridden System.Object.GetHashCode?</a>:</p>
  
  <pre><code>public override int GetHashCode()
  {
       return new { StepType, Color, Trigger, Delay, Index       }.GetHashCode();
  }
  </code></pre>
  
  <p>Note that all these properties, aside from Delay and Index, are reference types, not value types if that makes a difference.  And to answer someone's question: no the two list I'm comparing are definitely not the same references.  They are two separate lists.  Perhaps therein lies my issue.</p>