title: implement GetHashCode() for objects that contain collections
body: <p>Consider the following objects:</p>
  
  <pre><code>class Route
  {
     public int Origin { get; set; }
     public int Destination { get; set; }
  }
  </code></pre>
  
  <p>Route implements equality operators.</p>
  
  <pre><code>class Routing
  {
     public List&lt;Route&gt; Paths { get; set; }
  }
  </code></pre>
  
  <p>I used the code below to implement GetHashCode method for the Routing object and it seems to work but I wonder if that's the right way to do it? I rely on equality checks and as I'm uncertain I thought I'll ask you guys. Can I just sum the hash codes or do I need to do more magic in order to guarantee the desired effect?</p>
  
  <pre><code>public override int GetHashCode() =&gt;
  {
      return (Paths != null 
                  ? (Paths.Select(p =&gt; p.GetHashCode())
                          .Sum()) 
                  : 0);
  }
  </code></pre>
  
  <p>I checked several <code>GetHashCode()</code> questions here as well as MSDN and Eric Lippert's article on this topic but couldn't find what I'm looking for.</p>