title: C# Generic List Union Question
body: <p>I'm trying to merge 2 lists using "Union" so I get rid of duplicates. Following is the sample code:</p>
  
  <pre><code>public class SomeDetail
  {
      public string SomeValue1 { get; set; }
      public string SomeValue2  { get; set; }
      public string SomeDate { get; set; }
  }
  
  public class SomeDetailComparer : IEqualityComparer&lt;SomeDetail&gt;
  {
      bool IEqualityComparer&lt;SomeDetail&gt;.Equals(SomeDetail x, SomeDetail y)
      {
          // Check whether the compared objects reference the same data.        
          if (Object.ReferenceEquals(x, y))
              return true;
          // Check whether any of the compared objects is null.        
          if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
              return false;
          return x.SomeValue1 == y.SomeValue1 &amp;&amp; x.SomeValue2 == y.SomeValue2;
      }
      int IEqualityComparer&lt;SomeDetail&gt;.GetHashCode(SomeDetail obj)
      {
          return obj.SomeValue1.GetHashCode();
      }
  }
  
  List&lt;SomeDetail&gt; tempList1 = new List&lt;SomeDetail&gt;();
  List&lt;SomeDetail&gt; tempList2 = new List&lt;SomeDetail&gt;();
  
  List&lt;SomeDetail&gt; detailList = tempList1.Union(tempList2, SomeDetailComparer).ToList();
  </code></pre>
  
  <p>Now the question is can I use Union and still get the record which has the latest date (using SomeDate property). The record itself can either be in tempList1 or tempList2.</p>
  
  <p>Thanks in advance</p>