Difference between foreach and for loops over an IEnumerable class in C#

后端 未结 7 870
有刺的猬
有刺的猬 2020-12-17 17:00

I have been told that there is a performance difference between the following code blocks.

foreach (Entity e in entityList)
{
 ....
}

and <

相关标签:
7条回答
  • 2020-12-17 17:20

    In terms of allocations, it'd be better to look at this blogpost. It shows in exactly in what circumstances an enumerator is allocated on the heap.

    0 讨论(0)
提交回复
热议问题