C # How to view the Il code of the source program

Source: Internet
Author: User

1. Open the Microsoft Visual Studio 2008/Visual Studio Tools/Visual Studio 2008 command prompt and enter ildasm. As shown in:

2. Press enter to open the Il dasm window, as shown in:

3. Click file/open and open the compiled. EXE file to view the Il code of the Code.

For example, run the Visual Studio 2008 command to check the Il code of the following source program.

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

Namespace bubblesort
{
Class bubblesort1
{// Sort in ascending order. The maximum number of rows is placed at the end.
Public static void bubblesort (INT [] items)
{
Int I, j, temp;
If (items = NULL)
Return;
For (I = items. Length-1; I> = 0; I ++)
For (j = 1; j <= I; j ++)
If (items [J-1]> items [J])
{
Temp = items [J-1];
Items [J-1] = items [J];
Items [J] = temp;
}
}
}
}

 

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

Namespace bubblesort
{
Class bubblesort2
{
Public Enum sorttype
{
Ascending,
Descending
}
Public static void bubblesort (INT [] items, sorttype sortorder)
{
Int I, j, temp;
If (items = NULL)
Return;
For (I = items. Length-1; I> = 0; I ++)
{
For (j = 1; j <= I; j ++)
{
Switch (sortorder)
{
Case sorttype. ascending:
If (items [J-1]> items [J])
{
Temp = items [J-1];
Items [J-1] = items [J];
Items [J] = temp;

}
Break;
Case sorttype. Descending:
If (items [J-1] <items [J])
{
Temp = items [J-1];
Items [J-1] = items [J];
Items [J] = temp;
}
Break;
}

}
}
}
}
}

 

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

Namespace bubblesort
{
Public Delegate bool comparisonhandler (INT first, int second); // delegate type declaration
Class bubblesort3
{
Public static bool greaterthan (INT first, int second)
{// Sort in ascending order
Return first> second;
}
Public static bool lessthan (INT first, int second)
{// Sort in descending order
Return first <second;
}
Public static bool alphabeticalgreaterthan (INT first, int second)
{// Sort by alphabet. A. compareto (B): If A> B returns less than 0, a <B returns more than 0,
// A = B. The returned value is 0.
Int comparison;
Comparison = (first. tostring (). compareto (second. tostring ()));
Return comparison> 0;
}
Public static void bubblesort (INT [] items, comparisonhandler comparisonmethod)
{
Int I, j, temp;
If (items = NULL)
Return;
If (comparisonmethod = NULL)
Throw new argumentnullexception ("comparisonmethod ");
For (I = items. Length-1; I> = 0; I --)
{
For (j = 1; j <= I; j ++)
If (comparisonmethod (items [J-1], items [J])
{
Temp = items [J-1];
Items [J-1] = items [J];
Items [J] = temp;
}
}
}
}
}

 

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using bubblesort;

Namespace bubblesort
{
Class Program
{
Static void main (string [] ARGs)
{
Int intcount;
Console. writeline ("Enter the number of integer sequences to be sorted :");
Intcount = convert. toint32 (console. Readline ());
Console. writeline ("Enter the sequence of Integers to be sorted :");
Int [] items = new int [intcount];
For (INT I = 0; I <intcount; I ++)
{
Items [I] = convert. toint32 (console. Readline ());

}

Comparisonhandler comparisonmethod = bubblesort3.greaterthan;
Bubblesort3.bubblesort (items, comparisonmethod );
Console. writeline ("the sequence of integers after sorting by calling the sort method in the bubblesort3 class is :");
For (INT I = 0; I <intcount; I ++)
{
Console. Write (items [I]);
Console. Write ("");

}


}
}
}

 

The above program's il code:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.