1

私はこのアプリを書いて構築しました:

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;
            }
        }
    }
}

bin/Debug フォルダーの .exe に基づいて ILSpy でコードを表示すると、期待していたステート マシン コードが表示されません。 ここに画像の説明を入力

コンパイラが生成したコードを表示するにはどうすればよいですか?

4

1 に答える 1

2

You can go to "View->Option" and under the "Decompiler" tab, you can uncheck "C#2.0->Decompile enumerator(yield return)" : enter image description here

于 2021-03-27T10:20:43.393 に答える