The IL Disassembler tool is provided with Visual Studio. How can we use it? Much of the .NET Framework is implemented with itself. It is possible to inspect its internals the same way you can look at any program's internals. We inspect—but do not disassemble—the IL Disassembler.
This tutorial shows how to use the IL Disassembler program in Visual Studio.


Let's get started with the IL Disassembler. If you have installed Visual Studio, browse to your Microsoft Windows SDK folder and look for the cyan thunderbolt in the Tools subfolder. It might be worthwhile to create a shortcut to the program.

Because metadata for C# programs is stored in DLL files, you can open DLL files in IL Disassembler and look at the intermediate language embedded in them. Let's try the Microsoft .NET Framework itself for a demonstration. On my system, I can browse to this folder: C:\Windows\Microsoft.NET\Framework\v4.0.30319 to find all the DLL files the .NET Framework itself uses.
The most commonly used DLL file for the .NET Framework is mscorlib.dll. This file not the complete Framework, but stores the most common and important types. Open your mscorlib.dll file and look at the tree that appears. It is similar to the screenshot at the top of this article.
Use the tree widget to browse into the System.String type. To do this, open System and then browse to System.String. Here, you can see the String type methods available in C# programs and also the internal methods. Let's look at the Contains method next.
When you click on Contains, you will see a window with a yellow background. This shows the metadata header for this method, and then the method body which is encoded in IL instructions.

Method call. There is a call instruction in Contains. This points to the IndexOf method, which is also available for viewing in IL Disassembler. Contains is simply a wrapper method for IndexOf, after all.
Instructions. In Contains, we can see the ldarg, ldc, call, clt, ceq, and ret instructions. The ldarg instruction pushes one of the formal parameters to the method onto the evaluation stack. The ldc instruction pushes a constant (specified directly) onto the stack. Call transfers control to the specified method, passing the values on the evaluation stack as arguments. The clt instruction compares two values with a less than operation; ceq compares two values with an equals operation. Ret simply transfers control to whatever method called the Contains method.
The IL Disassembler tool has several options on it. With "Show bytes", you can see the original bytes that are being interpreted by the disassembler. With "Quote all names", you can put type names inside quotation marks. With "Statistics", you can see interesting information about the DLL or EXE file you loaded. With Dump, you can write the IL code from a DLL or EXE to a set of files.

The IL Disassembler tool is worth looking into for people who want to learn more about the .NET Framework. It helps to have a basic understanding of the intermediate language, and how the evaluation stack works. For practical development, IL Disassembler can instantly tell you what methods are called inside a certain Framework method. This helps cultivate an understanding of how the .NET Framework works, which will yield improvements in program quality.
Intermediate Language