Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 )
{
...
}
like image 694
Joan Venge Avatar asked Apr 09 '26 00:04

Joan Venge


1 Answers

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

like image 134
Kirk Woll Avatar answered Apr 10 '26 14:04

Kirk Woll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!