title: Remove duplicates in a list (c#)
body: <p>I want to remove duplicates in a list using following code, but it does not work. Anyone could enlighten me? Thanks.</p>
  
  <pre><code>public sealed class Pairing
  {
      public int Index { get; private set; }
      public int Length { get; private set; }
      public int Offset { get; private set; }
  
      public Pairing(int index, int length, int offset)
      {
          Index = index;
          Length = length;
          Offset = offset;
      }
  }
  
  
  class MyComparer : IEqualityComparer&lt;Pairing&gt;
  {
      public bool Equals(Pairing x, Pairing y)
      {
          return ((x.Index == y.Index) &amp;&amp; (x.Length == y.Length) &amp;&amp; (x.Offset == y.Offset));
      }
  
      public int GetHashCode(Pairing obj)
      {
          return obj.GetHashCode();
      }
  }
  class Program
  {
      static void Main(string[] args)
      {
          List&lt;Pairing&gt; ps = new List&lt;Pairing&gt;();
          ps.Add(new Pairing(2, 4, 14));
          ps.Add(new Pairing(1, 2, 4));
          ps.Add(new Pairing(2, 4, 14));
  
          var unique = ps.Distinct(new MyComparer());
          foreach (Pairing p in unique)
          {
              Console.WriteLine("{0}\t{1}\t{2}", p.Index, p.Length, p.Offset);
          }
          Console.ReadLine();
      }
  }
  </code></pre>