Currently I'm working with some libraries applying deferred execution via iterators. In some situations I have the need to "forward" the recieved iterator simply. I.e. I have to get the IEnumerable<T>
instance from the called method and return it immediately.
Now my question: Is there a relevant difference between simply returning the recieved IEnumerable<T>
or re-yielding it via a loop?
IEnumerable<int> GetByReturn()
{
return GetIterator(); // GetIterator() returns IEnumerable<int>
}
// or:
IEnumerable<int> GetByReYielding()
{
for(var item in GetIterator()) // GetIterator() returns IEnumerable<int>
{
yield return item;
}
}