How to view C# IL code using IL DASM tool

Sourav.Kayal
Posted by in C# category on for Beginner level | Points: 250 | Views : 4206 red flag

Let's look at how to view IL code using ILDASM tool

How to view C# IL code using IL DASM tool

We all know C# is platform independent language like java. And the beauty of platform independent language is it can run anywhere. Means, if we compile a piece of code in my 32 bit system and try to run in 64 bit operating system it will work smoothly. This is called platform independent.

So, .NET framework does not generate native code directly when we compile any C# program.  Rather than generating native code .NET framework generates one half compiled code called intermediate language. And this intermediate language is taken by JIT (Just in time) compiler to produce native code.

If we want to see intermediate code we can check it by using ILDASM. Those who are not familiar with IL DASM below few lines are for them.

IL DASM is a tool provided by Visual Studio to open IL code. We can find IL DASM tool by going Visual Studio option through all programs.





How to use IL DASM to see IL code

At first we have to write program and need to compile it. After compilation we can open generated exe file in IL DASM tool and we can view half compiled code. In below I am showing steps.

1)      Write program in C#

I have written a simple program to show IL code. Here is my C# code.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace Test1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Hello world");
            Console.ReadLine();
        }
    }
}

       2)      Compile and debug it by pressing F5 key.


       3)      Open IL DASM tool and select exe file by going to proper file location of your current program.

 

       4)      Open .exe file using IL DASM

 

       5)      Double click on Main() function



conclusion :

       Those are steps to view IL code using IL DASM tool. Hope this is helpful.

Page copy protected against web site content infringement by Copyscape

About the Author

Sourav.Kayal
Full Name: Sourav Kayal
Member Level: Silver
Member Status: Member,MVP
Member Since: 6/20/2013 2:09:01 AM
Country: India
Read my blog here http://ctrlcvprogrammer.blogspot.in/
http://www.dotnetfunda.com
I am .NET developer working for HelixDNA Technologies,Bangalore in healthcare domain. Like to learn new technology and programming language. Currently working in ASP.NET ,C# and other microsoft technologies.

Login to vote for this post.

Comments or Responses

Posted by: Anup1252000 on: 7/15/2013 | Points: 25
Good one :).

But you need to elaborate more on other things like manifest. What will happen if you add dll in GAC? Then you need to explain what is version and publick key token of the dll? What is strong name?

There are some interesting topic on ildasm like
1) What would be the type of delegate in Ildasm? In this case, delegate will be generated as class. Go through this.
2) What will happen if you add same dll with different version of dll?

Login to post response

Comment using Facebook(Author doesn't get notification)