title: Flatten IEnumerable<IEnumerable<>>; understanding generics
body: <p>I wrote this extension method (which compiles):</p>
  
  <pre><code>public static IEnumerable&lt;J&gt; Flatten&lt;T, J&gt;(this IEnumerable&lt;T&gt; @this) 
                                             where T : IEnumerable&lt;J&gt;
  {
      foreach (T t in @this)
          foreach (J j in t)
              yield return j;
  }
  </code></pre>
  
  <p>The code below causes a compile time error (no suitable method found), <strong>why?</strong>:</p>
  
  <pre><code>IEnumerable&lt;IEnumerable&lt;int&gt;&gt; foo = new int[2][];
  var bar = foo.Flatten();
  </code></pre>
  
  <p>If I implement the extension like below, I get no compile time error:</p>
  
  <pre><code>public static IEnumerable&lt;J&gt; Flatten&lt;J&gt;(this IEnumerable&lt;IEnumerable&lt;J&gt;&gt; @this)
  {
      foreach (IEnumerable&lt;J&gt; js in @this)
          foreach (J j in js)
              yield return j;
  }
  </code></pre>
  
  <p><strong>Edit(2)</strong>: This question I consider answered, but it raised another question regarding overload resolution and type constraints. This question I put here: <a href="https://stackoverflow.com/questions/9440888">Why aren&#39;t type constraints part of the method signature?</a></p>