title: C# - Does function get called for each iteration of a foreach loop?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1632810/how-does-foreach-work-when-looping-through-function-results">How does foreach work when looping through function results?</a>  </p>
  </blockquote>
  
  
  
  <p>If I have functionality like the following - will ReturnParts() get called for each iteration in a foreach loop, or will it get called just the once? </p>
  
  <pre><code>private void PrintParts()
  {
       foreach(string part in ReturnParts())
       {
           // Do Something or other. 
       }
  }
  
  private string[] ReturnParts()
  {
       // Build up and return an array. 
  }
  </code></pre>