Is it possible to mark a foreach loop code block and convert it to a for loop using ReSharper?
Or with Visual Studio?
Thank!
Yep ReShaper can do this. Tested in VS2010 + R # 5
Before:
var a = new int[] {1, 2, 3, 4}; foreach (var i in a) { }
After:
var a = new int[] {1, 2, 3, 4}; for (int index = 0; index < a.Length; index++) { var i = a[index]; }
works fine, as rdkleine said, and the sample works fine.BUT: if your collection is simple IEnumerable<T>, it will not work (reasonably).
IEnumerable<T>