title: Key comparisons for Linq GroupBy using Default EqualityComparer
body: <p>I'm trying to do a Linq GroupBy on some objects using an explicit key type. I'm not passing an <code>IEqualityComparer</code> to the GroupBy, so according to the docs: </p>
  
  <blockquote>
    <p>The default equality comparer <code>Default</code> is used to compare keys.</p>
  </blockquote>
  
  <p>It explains the <code>EqualityComparer&lt;T&gt;.Default</code> property like this:</p>
  
  <blockquote>
    <p>The <code>Default</code> property checks whether
    type <code>T</code> implements the
    <code>System.IEquatable&lt;T&gt;</code> generic interface
    and if so returns an
    <code>EqualityComparer&lt;T&gt;</code> that uses that
    implementation.</p>
  </blockquote>
  
  <p>In the code below, I'm grouping an array of <code>Fred</code> objects. They have a key type called <code>FredKey</code>, which implements <code>IEquatable&lt;FredKey&gt;</code>.</p>
  
  <p>That should be enough to make the grouping work, but the grouping is not working. In the last line below I should have 2 groups, but I don't, I just have 3 groups containing the 3 input items.</p>
  
  <p>Why is the grouping not working?</p>
  
  <pre><code>class Fred
  {
      public string A;
      public string B;
      public FredKey Key
      {
          get { return new FredKey() { A = this.A }; }
      }
  }
  
  class FredKey : IEquatable&lt;FredKey&gt;
  {
      public string A;
      public bool Equals(FredKey other)
      {
          return A == other.A;
      }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          var f = new Fred[]
          {
              new Fred {A = "hello", B = "frog"},
              new Fred {A = "jim", B = "jog"},
              new Fred {A = "hello", B = "bog"},
          };
  
          var groups = f.GroupBy(x =&gt; x.Key);
          Debug.Assert(groups.Count() == 2);  // &lt;--- fails
      }
  }
  </code></pre>