I'm new to C# and .net, sorry if my question sounds stupid.
I follow an onlilne tutorial which teaches how to insepect compiled code, below is a snapshot from the instructor:
And below is a screenshot from my pc:
You can see that mine is purely IL code, and even if I change the setting to C#: there is no
<Main>d_0
section anymore, and the code is purely C# code. so how can I switch to the view so that I can see the "more advanced C# code" just like the instructor's?
You're using a more modern version of ILSpy compared to your instructor. Your more modern version can better reverse C#'s newer language-features to simpler C# code.
For example, older versions of ILSpy could not decompile async
methods with await
keywords back into single source methods, but instead would show them as their compiled multi-method state-machines (as you're seeing with how TaskAwaiter
is exposed in <Main>d_0
).
If you want the same display as your instructor you need to use the same version of ILSpy as them. From the screenshot it looks like they're using version 4 or earlier of ILSpy - which is very outdated by now. You should tell your instructor to get the latest version (as of November 2020 it's version 6.1).
The ILSpy toolbar has a group of buttons that lets you choose between
If you pick "Show all types and members" you'll see the compiler-generated class and its MoveNext method even if decompilation of the async
feature is enabled.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.