1

I've written this app:

using System.Collections.Generic;
using System;

namespace Test
{
    
    class Program
    {
        static void Main(string[] args)
        {
            var myClass = new MyClass();
            foreach (var item in myClass.CountFrom(1, 4))
            {
                Console.WriteLine(item);                
            }
            Console.Read();
        }
    }

    public class MyClass
    {
        public IEnumerable<int> CountFrom(int start, int limit)
        {
            for (int i = start; i <= limit; i++)
            {
                yield return i;
            }
        }
    }
}

The compiler generated code can be found here.

What is the easiest way to convert the compiler generated C# code into code that I can copy/paste into VS and debug? I'd prefer to not have to do replace all for the non C# names.

The same question has been asked before but with no answer.

David Klempfner
  • 8,700
  • 20
  • 73
  • 153
  • I'm not sure what your ultimate goal is. You want to "debug" the compiler generated code? Why not just debug the code that you wrote? They should do the same thing, right? – Sweeper Mar 27 '21 at 10:10
  • Because as soon as you F11 on yield return, it does not go into the state machine code, it skips over it and goes back into the foreach, which does not help me when it comes to learning how the state machine code works. – David Klempfner Mar 27 '21 at 10:12
  • For learning purposes, I would recommend replacing the names by hand, or even building the state machine on your own. That way you learn a lot more. – Sweeper Mar 27 '21 at 10:16
  • Replacing the names by hand won't help me learn more. – David Klempfner Mar 27 '21 at 10:28

0 Answers0