title: Remove duplicates while merging lists using Union in LINQ
body: <p>I am trying to merge two lists using <code>list.Union</code> in <code>LinqPad</code> but I can't get it to work and wanted to check my understanding is correct.</p>
  
  <p>Given this simple class:</p>
  
  <pre><code>public class Test 
  {
     public int Id { get; set;}
     public int field1 { get; set; }
  
     public bool Equals(Test other)
     {        
        return this.Id.Equals(other.Id);
     }
  }
  </code></pre>
  
  <p>And two lists populated like this:</p>
  
  <pre><code>List&lt;Test&gt; list = new List&lt;Test&gt;();
  list.Add( new Test { Id = 1, field1 = 1});
  list.Add( new Test { Id = 1, field1 = 2});
  list.Add( new Test { Id = 2, field1 = 3});
  list.Add( new Test { Id = 2, field1 = 4});
  
  List&lt;Test&gt; list2 = new List&lt;Test&gt;();
  list2.Add( new Test { Id = 1, field1 = 1});
  list2.Add( new Test { Id = 1, field1 = 2});
  list2.Add( new Test { Id = 2, field1 = 3});
  list2.Add( new Test { Id = 2, field1 = 4});
  </code></pre>
  
  <p>I then try: <code>var mergedList = list.Union(list2).ToList();</code> and output the data using a simple <code>foreach</code> loop and get this output:</p>
  
  <pre><code>ID: 1 -------- 1
  ID: 1 -------- 2
  ID: 2 -------- 3
  ID: 2 -------- 4
  ID: 1 -------- 1
  ID: 1 -------- 2
  ID: 2 -------- 3
  ID: 2 -------- 4
  </code></pre>
  
  <p>I was under the impression that <code>Union</code> should remove the duplicates to return:</p>
  
  <pre><code>ID: 1 -------- 1
  ID: 1 -------- 2
  ID: 2 -------- 3
  ID: 2 -------- 4
  </code></pre>
  
  <p>Am I doing something wrong or have I misunderstood?</p>
  
  <p>Also, should it work without explicitly overriding the <code>Equals</code> method in the <code>Test</code> class?</p>
  
  <p>Thanks</p>