title: How do I use a custom comparer with the Linq Distinct method?
body: <p>I was reading a book about Linq, and saw that the Distinct method has an overload that takes a comparer. This would be a good solution to a problem I have where I want to get the distinct entities from a collection, but want the comparison to be on the entity ID, even if the other properties are different.</p>
  
  <p>According to the book, if I have a Gribulator entity, I should be able to create a comparer like this...</p>
  
  <pre><code>private class GribulatorComparer : IComparer&lt;Gribulator&gt; {
    public int Compare(Gribulator g1, Gribulator g2) {
      return g1.ID.CompareTo(g2.ID);
    }
  }
  </code></pre>
  
  <p>...and then use it like this...</p>
  
  <pre><code>List&lt;Gribulator&gt; distinctGribulators
    = myGribulators.Distinct(new GribulatorComparer()).ToList();
  </code></pre>
  
  <p>However, this gives the following compiler errors...</p>
  
  <p>'System.Collections.Generic.List' does not contain a definition for 'Distinct' and the best extension method overload 'System.Linq.Enumerable.Distinct(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEqualityComparer)' has some invalid arguments</p>
  
  <p>Argument 2: cannot convert from 'LinqPlayground.Program.GribulatorComparer' to 'System.Collections.Generic.IEqualityComparer'</p>
  
  <p>I've searched around a bit, and have seen plenty of examples that use code like this, but no complaints about compiler errors.</p>
  
  <p>What am I doing wrong? Also, is this the best way of doing this? I want a one-off solution here, so don't want to start changing the code for the entity itself. I want the entity to remain as normal, but just in this one place, compare by ID only.</p>
  
  <p>Thanks for any help.</p>