Possible Duplicate:
How does foreach work when looping through function results?
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.
}
It will be called just once.
P.S. Calling it multiple times would make little sense. You would call it each time anew if you expected the result to be different each time. And how would you iterate over a continuously changing set?