title: EqualityComparer<T>.Default vs. T.Equals
body: <p>Suppose I've got a generic <code>MyClass&lt;T&gt;</code> that needs to compare two objects of type <code>&lt;T&gt;</code>. Usually I'd do something like ...</p>
  
  <pre><code>void DoSomething(T o1, T o2)
  {
    if(o1.Equals(o2))
    {
      ...
    }
  }
  </code></pre>
  
  <p>Now suppose my <code>MyClass&lt;T&gt;</code> has a constructor that supports passing a custom <code>IEqualityComparer&lt;T&gt;</code>, similar to <a href="http://msdn.microsoft.com/en-us/library/ms132072.aspx"><code>Dictionary&lt;T&gt;</code></a>. In that case I'd need to do ...</p>
  
  <pre><code>private IEqualityComparer&lt;T&gt; _comparer;
  public MyClass() {}
  public MyClass(IEqualityComparer&lt;T&gt; comparer)
  {
    _comparer = comparer;
  }
  void DoSomething(T o1, T o2)
  {
    if((_comparer != null &amp;&amp; _comparer.Equals(o1, o2)) || (o1.Equals(o2)))
    {
      ...
    }
  }
  </code></pre>
  
  <p>To remove this lengthy if statement, it'd be good if I could have <code>_comparer</code> default to a 'default comparer' if the regular constructor is used. I searched for something like <code>typeof(T).GetDefaultComparer()</code> but wasn't able to find anything like it.</p>
  
  <p>I did find <a href="http://msdn.microsoft.com/en-us/library/ms224763.aspx"><code>EqualityComparer&lt;T&gt;.Default</code></a>, could I use that? And would then this snippet ...</p>
  
  <pre><code>public MyClass()
  {
    _comparer = EqualityComparer&lt;T&gt;.Default;
  }
  void DoSomething(T o1, T o2)
  {
    if(_comparer.Equals(o1, o2))
    {
      ...
    }
  }
  </code></pre>
  
  <p>... provide the same results as using <code>o1.Equals(o2)</code> for all possible cases?</p>
  
  <p>(As a side note, would this mean I'd also need to use any special generic constraint for <code>&lt;T&gt;</code>?)</p>