Performance of the Loops … in C#

As strange as one might think, the topic of the performance of loops in C# is not that trivial. I am talking here about high performance applications where every millisecond counts.

Consider an array of 100 millions integers, that you want to scan as fast as you can. What would be the right way to do it ?

C# provides several ways to loop over an array or a collection:

  • for, while
  • foreach
  • Array.ForEach()

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store