how to get the assembly code of the code?

mc 3,701 Reputation points
2022-12-19T14:45:16.737+00:00

I want to get the assembly code of the code how to do it using .net?

If I have one code:

int i = 10;  

how to get its assembly code

mov eax 10;  
ret;  
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,396 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,188 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
323 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 48,581 Reputation points
    2022-12-19T15:23:15.777+00:00

    Run it through a disassembler such as ILDasm, JustDecompiler or dotPeek.

    0 comments No comments

  2. Bruce (SqlWork.com) 56,766 Reputation points
    2022-12-19T17:27:25.73+00:00

    .net code is only converted to assembly at runtime. to see the assembly, you need a debugger that supports the display.

    visual studio has one. under debug options enable address level debugging and use the disassembly window:

    https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-use-the-disassembly-window?view=vs-2022

    visual studio code debugger also has support:

    https://www.strathweb.com/2020/05/decompilation-support-in-omnisharp-and-c-extension-for-vs-code/