title: LINQ GroupBy Anonymous Type
body: <p>I am wondering why GroupBy works with anonymous types.</p>
  
  <pre><code>List&lt;string&gt; values = new List&lt;string&gt;();
  values.GroupBy(s =&gt; new { Length = s.Length, Value = s })
  </code></pre>
  
  <p>Anonymous types do not implement any interfaces, so I am confused how this is working. </p>
  
  <p>I assume that the algorithm is working by creating an instance of the anonymous type for each item in the source and using hashing to group the items together. However, no IEqualityComparer is provided to define how to generate a hash or whether two instances are equal. I would assume, then, that the Object.Equals and Object.GetHashCode methods would be the fallback, which rely on object identity.</p>
  
  <p>So, how is it that this is working as expected? And yet it doesn't work in an OrderBy. Do anonymous types override Equals and GetHashCode? or does the underlying GroupBy algorithm do some magic I haven't thought of?</p>