In .NET, which loop runs faster, 'for' or 'foreach'?

前端 未结 30 1376
抹茶落季
抹茶落季 2020-11-22 04:25

In C#/VB.NET/.NET, which loop runs faster, for or foreach?

Ever since I read that a for loop works faster than a foreach

30条回答
  •  难免孤独
    2020-11-22 04:46

    The two will run almost exactly the same way. Write some code to use both, then show him the IL. It should show comparable computations, meaning no difference in performance.

提交回复
热议问题