Why implement IEqualityComparer<T> in a separate class
<p>When I was looking up the generic <code>IEqualityComparer</code> interface on <a href="https://msdn.microsoft.com/en-us/library/ms132151%28v=vs.110%29.aspx?f=255&amp;MSPPError=-2147217396" rel="noreferrer">msdn</a> I noticed the interface was implemented in a separate 'comparer' class, opposed to <code>IEquatable&lt;T&gt;</code> which is implemented in the class itself. When I searched for some more examples, every single one was using a separate class and that got me wondering: <strong>why not implement it on the class itself?</strong> </p>

<p>I can imagine overriding <code>object.Equals</code> and <code>object.GetHashCode</code> isn't considered good practice because it's used in a lot of different situations, but even msdn says (emphasis mine):</p>

<blockquote>
  <p>This interface allows the implementation of customized equality comparison for <strong>collections</strong>.</p>
</blockquote>

<p>so its uses are pretty much limited to Linq. There's only 2 reasons I can think of why to define a separate comparer class:</p>

<ol>
<li>Different methods on a collection of the class require a different comparer.</li>
<li>The class is big and instantiating another object of it isn't desired (although if that's really the issue, why isn't having a whole collection of it not bad?).</li>
</ol>

<p><strong>So my question is:</strong></p>

<p>Is there any particular reason that I overlooked which causes everyone to define another comparerclass just for comparing instead of just implementing the interface on the class itself (which would not be worse in my opinion to say the least)?</p>

<p>A small example:</p>

<pre><code>public static void Main(string[] args)
{
    Test t1 = new Test { id = 1, date = default(DateTime) };
    Test t2 = new Test { id = 1, date = default(DateTime) };
    Test t3 = new Test { id = 0, date = default(DateTime) };
    List&lt;Test&gt; testList = new List&lt;Test&gt;{ t1, t2, t3 };

    //Same result
    int distinctCountClass = testList.Distinct(new Test()).Count();
    int distinctCountComparerClass = testList.Distinct(new TestComparer()).Count();
}

public partial class Test
{
    public int id { get; set; }
    public DateTime date { get; set; }
}

public partial class Test : IEqualityComparer&lt;Test&gt;
{
    public bool Equals(Test x, Test y) { return x.id == y.id &amp;&amp; x.date == y.date; }
    public int GetHashCode(Test obj) { return obj.id.GetHashCode(); }
}

public class TestComparer : IEqualityComparer&lt;Test&gt;
{
    public bool Equals(Test x, Test y) { return x.id == y.id &amp;&amp; x.date == y.date; }
    public int GetHashCode(Test obj) { return obj.id.GetHashCode(); }
}
</code></pre>