Tuesday, March 08, 2011

Disassemble code in Visual Studio instead of ILDSAM disassembler

Introduction:
Most of the times when we want to see the disassembled code we will go for the ILDASM tool and give the mapped path of the dll and see the disassembled code in the tool. Now we have an option for that in Visual Studio itself. Let's see in this article on how to do this step by step.

Steps:

Let's open a console application and make a small application and see how visual studio disassembles the code and shows the output.

Create a console application and place the below code in the main method.

try
{
    Console.Write("Please Enter the Year: ");
    int year = int.Parse(Console.ReadLine());
    if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
    {
        Console.WriteLine("The year {0}, is a Leap Year", year);
    }
    else
    {
        Console.WriteLine("The year {0}, is not a Leap Year", year);
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}
Console.ReadLine();

Place a break point at the execution end level to see the disassembled code as shown in the below image
...

Now right click on the code and u can see the option Go To Disassembly as shown in the below image

Disassemble3.gif  Disassemble4.gif

Read more: C# Corner