For vs. For Each vs. While in C#
See the original posting on DZone Python
I am often asked by some people/colleagues, "which loop is faster?" "Which loop has higher performance?" Etc. I have heard that the For loop is faster than the For…each loop but I have never tried it before. So, I decided to see how big the difference is among all the loops and which one is faster at looping through an array and a list in terms of speed and performance.
Let’s start our journey to fin the best C# loop. For this exercise, I’ll be creating a console application in Visual Studio 2017.