C# - Does function get called for each iteration of a foreach loop?

Posted by Robert W on Stack Overflow See other posts from Stack Overflow or by Robert W
Published on 2010-03-15T13:47:52Z Indexed on 2010/03/15 13:49 UTC
Read the original article Hit count: 175

Filed under:
|

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?

private void PrintParts()
{
     foreach(string part in ReturnParts())
     {
         // Do Something or other. 
     }
}

private string[] ReturnParts()
{
     // Build up and return an array. 
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about syntax