title: Strange execution order when using nested method, yield return and using in combination
body: <p>I'm unable to understand why <code>Program.Fetch1</code> and <code>Program.Fetch2</code> do not result in the exact same execution order. The only difference is that <code>Program.Fetch1</code> is calling <code>Program.Fetch</code> to do the actual fetch operation.</p>
  
  <pre><code>class Program
  {
      static IEnumerable&lt;int&gt; Fetch1()
      {
          using (Context c = new Context())
          {
              return Fetch(c);
          }
      }
  
      static IEnumerable&lt;int&gt; Fetch(Context c)
      {
          foreach (int i in c.Fetch())
          {
              yield return i;
          }
      }
  
      static IEnumerable&lt;int&gt; Fetch2()
      {
          using (Context c = new Context())
          {
              foreach (int i in c.Fetch())
              {
                  yield return i;
              }
          }
      }
  
      static void Main(string[] args)
      {
          Console.WriteLine("Fetch1:");
          foreach (int i in Fetch1())
          {
              Console.WriteLine(i);
          }
          Console.WriteLine("Fetch2:");
          foreach (int i in Fetch2())
          {
              Console.WriteLine(i);
          }
      }
  }
  
  
  class Context : IDisposable
  {
  
      public void Dispose()
      {
          Console.WriteLine("Context.Dispose");
      }
  
      public IEnumerable&lt;int&gt; Fetch()
      {
          return new int[] { 1, 2 };
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Fetch1:
  Context.Dispose
  1
  2
  Fetch2:
  1
  2
  Context.Dispose
  </code></pre>
  
  <p>My only guess is that <code>Context.Dispose</code> is called first in <code>Program.Fetch1</code> because the scope of the using declaration was already left. But this is true for <code>Program.Fetch1</code> as well. So why do those method behave differently?</p>
  
  <p><strong>Update:</strong> My question is a duplicate of <a href="https://stackoverflow.com/questions/1539114/yield-return-statement-inside-a-using-block-disposes-before-executing">yield return statement inside a using() { } block Disposes before executing</a></p>