Microsoft document: "Code Review: .NET Application Performance" (http://msdn.microsoft.com/en-us/library/ff647802.aspx) recommends "for" loop instead of foreach loop to improve the performance.
Do You Use foreach?
Using foreach can result in extra overhead because of the way enumeration is implemented in .NET Framework collections. .NET Framework 1.1 collections provide an enumerator for the foreach statement to use by overriding the IEnumerable.GetEnumerator.
...
Consider using a for loop instead of foreach to increase performance for iterating through .NET Framework collections that can be indexed with an integer.
My application does expensive call every time user click on a row in grid in a loop. It is about 2 million iteration to convert from floating point values to Color that will be visualized in the monitor.
I am not sure to use for loop instead foreach loop because Resharper make a warning in every for loop which can be converter to foreach loop.
1. Why does Resharper Recommend foreach Instead of for Loop?
2. Is it safe to use for loop?