title: What happens to GetEnumerator() method when yield return is used?
body: <p>Learning the collections and IEnumerable and IEnumerator interfaces.
  I have the below program. WHen i step into the </p>
  
  <pre><code>IEnumerator&lt;string&gt; name = sample.GetEnumerator();
  </code></pre>
  
  <p>it calls the <code>Console.WriteLine("inside getenumerator");</code></p>
  
  <pre><code>class Program
      {
          static void Main(string[] args)
          {
              SampleStrings sample = new SampleStrings();
              IEnumerator&lt;string&gt; name = sample.GetEnumerator();
              foreach (var item in sample)
              {
                  Console.WriteLine(item);
              }
              Console.ReadLine();
          }
      }
      class SampleStrings : IEnumerable&lt;string&gt;
      {
          public IEnumerator&lt;string&gt; GetEnumerator()
          {
              Console.WriteLine("inside getenumerator");
  
              return null;//for testing purpose only
          }
  
          System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
          {
              return this.GetEnumerator();
          }
      }
  </code></pre>
  
  <p>Now if I replace the GetEnumerator as below when the same <code>IEnumerator&lt;string&gt; name = sample.GetEnumerator();</code>
  is called then it does not step into the function. I would expect it to step into the function but not return anything since i did not call <code>movenext()</code> yet.
  What is happening when i specify yield that makes it behave this way. The program works.</p>
  
  <pre><code>public IEnumerator&lt;string&gt; GetEnumerator()
          {
              Console.WriteLine("inside getenumerator");
              yield return "First";
              yield return "Second";
  
          }
  </code></pre>