foreach variable declared twice when enumerating over ValueCollection twice

2 posts, 0 answers
  1. Thomas
    Thomas avatar
    4 posts
    Member since:
    Mar 2016

    Posted 11 Jan 2017 Link to this post

    The original code:

            public void Test(Dictionary<int, int> counters) {
                foreach (var counter in counters.Values) {
                    Console.WriteLine(counter);
                }

                foreach (var counter in counters.Values) {
                    Console.WriteLine(counter);
                }
            }

     

    Decompiles into:

            public void Test(Dictionary<int, int> counters)
            {
                int counter = 0;
                foreach (int counter in counters.Values)
                {
                    Console.WriteLine(counter);
                }
                foreach (int value in counters.Values)
                {
                    Console.WriteLine(value);
                }
            }

     

    Which doesn't compile because counter is declared twice.

    if the second foreach is removed it works.
    It also seems to work with arrays.

  2. Adrian
    Admin
    Adrian avatar
    17 posts

    Posted 17 Jan 2017 Link to this post

    Hi Thomas,

    I cannot reproduce this decompilation output, could you tell me which version of JustDecompile do you use for this decompilation result. 

    Would it be possible that you zip the assembly where that happens and send it over to me? Rather unfortunately, that seems to be the only way to reproduce that problem.

    Regards,
    Adrian
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top