Joan Venge
Joan Venge

Reputation: 330912

Would there be any performance difference between these 2 IEnumerable<T> codes using foreach?

var effects = this.EffectsRecursive;
foreach ( Effect effect in effects )
{
...
}

vs

foreach ( Effect effect in this.EffectsRecursive )
{
...
}

Upvotes: 2

Views: 102

Answers (1)

Kirk Woll
Kirk Woll

Reputation: 77546

No, the foreach operates on the result of the call to IEnumerable.GetEnumerator, which will get called only once either way.

Upvotes: 10

Related Questions