.netilspy

Configure ILSpy to show details behind generated code for local method


I trying to see compiler's code for this little sample:

static void Main()
{
    int i = 0;
    AddToI(5);
    AddToI(10);
    Console.WriteLine(i);
    void AddToI(int amount) => i += amount;
}

I am using ILSpy and it is showing me code almost identical to the original. But I expected compiler to add some class or structure?

Maybe I can tune ILSpy to show me more details?


Solution

  • You can select a lower language version (e.g. C# 6) in the toolbar to prevent ILSpy from using newer features.

    You also can turn off individual language features in View>Options>Decompiler.

    To quickly see "what does this code compile to?", you can use https://sharplab.io. SharpLab's C# mode also uses the ILSpy decompiler, but with almost all features disabled.