For vs Foreach on arrays and lists
As promised earlier in the week, here are the results of benchmarking for and foreach. For each of int and double, I created an array and a List<T>, filled it with random data (the same for the list as the array) and ran each of the following ways of summing the collection: A simple for loop, testing the index against the array length / list count each time A for loop with an initial variable remembering the length of the array, then comparing the index against the variable each time A foreach loop against the collection with the type known … Continue reading For vs Foreach on arrays and lists