views:

29

answers:

1

Hi,

Is it possible to mark a foreach loop code block and convert it to a for loop with ReSharper?

Or with Visual Studio?

Thanks!

+1  A: 

Yep ReShaper can do that. Tested it 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];
    }
rdkleine