title: Yield return in recursion doesn't return value even after ".ToList()" call
body: <p>When I make a call to generation permutations, 2nd <code>GeneratePermutations(list, startCount, permutationCount)</code> do yield return 6 times (<code>yield return permutationList;</code>). But for some reason, <code>result</code> in the first <code>GetPermutations</code> doesn't contain anything even though I did called <code>.ToList()</code> on the result.</p>
  
  <p>Does this have anything to do recursion?</p>
  
  <p><code>Test.cs</code></p>
  
  <pre><code>IEnumerable&lt;int[]&gt; actual = _sut.GetPermutations(3).ToList();
  </code></pre>
  
  <p><code>Perm.cs</code></p>
  
  <pre><code>public class Perm
  {
      public IEnumerable&lt;int[]&gt; GetPermutations(int permutationCount)
      {
          int[] permutationList = Enumerable.Range(1, permutationCount).ToArray();
          IEnumerable&lt;int[]&gt; result = GeneratePermutations(permutationList, 0, permutationCount - 1).ToList();
  
          // Doesn't contain any value!
          return result;
      }
  
      // http://stackoverflow.com/a/756083/4035
      private IEnumerable&lt;int[]&gt; GeneratePermutations(int[] permutationList, int startCount, int permutationCount)
      {
          if (startCount == permutationCount)
          {
              // Does return 6 times here.
              yield return permutationList;
          }
          else
          {
              for (int i = startCount; i &lt;= permutationCount; i++)
              {
                  Swap(ref permutationList, startCount, i);
                  GeneratePermutations(permutationList, startCount + 1, permutationCount).ToList();
                  Swap(ref permutationList, startCount, i);
              }
  
          }
      }
  
      // http://stackoverflow.com/a/2094316/4035
      public static void Swap(ref int[] list, int index1, int index2)
      {
          int tmp = list[index1];
          list[index1] = list[index2];
          list[index2] = tmp;
      }
  }
  </code></pre>