博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 如何查看源程序的IL代码
阅读量:4476 次
发布时间:2019-06-08

本文共 2996 字,大约阅读时间需要 9 分钟。

 1、打开microsoft  visual  studio  2008  /  visual  studio  tools /  visual  studio  2008 命令提示  ,并输入ildasm 。如下图所示:

2、按enter键,打开IL DASM 窗口,如下图所示:

3、单击 文件 / 打开,打开编译好的.exe文件,即可查看该代码的IL代码

例如:通过visual  studio  2008 命令提示 查看如下源程序的IL代码。

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BubbleSort

{
   class BubbleSort1
    {//升序排序,每一趟都将最大的一个数放在最后
        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);//委托类型的声明
    class BubbleSort3
    {
        public static bool GreaterThan(int first, int second)
        {//升序排序
            return first > second;
        }
        public static bool LessThan(int first, int second)
        {//降序排序
            return first < second;
        }
        public static bool AlphabeticalGreaterThan(int first, int second)
        {//按照字母表排序。a.CompareTo(b):若a>b 返回值小于0, a<b返回值大于0,
            //a=b返回值等于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("请输入待排序的整数序列的个数:");
            intcount = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入待排序的整数序列:");
            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("调用类BubbleSort3中的排序方法排序后的整数序列为:");
            for(int i=0;i<intcount;i++)
            {
                Console.Write(items[i]);
                Console.Write("   ");

            }

        }
    }
}

 

以上程序的IL代码:

 

转载于:https://www.cnblogs.com/worfdream/articles/2407241.html

你可能感兴趣的文章
多标签分类(multi-label classification)综述
查看>>
史上最全面的Spring-Boot-Cache使用与整合
查看>>
图的遍历(深度优先与广度优先搜索两种方案)
查看>>
快速读入模板
查看>>
\n ^ \t的使用
查看>>
css盒模型
查看>>
探索式测试:测试自动化
查看>>
make install fping
查看>>
面试笔试题
查看>>
#loj3051 [十二省联考2019] 皮配
查看>>
MySql可视化工具MySQL Workbench使用教程
查看>>
个人站立会议第二阶段07
查看>>
云时代架构阅读笔记五——Web应用安全
查看>>
IOS 单击手势和cell点击冲突
查看>>
学习_HTML5_day3
查看>>
计算机网络与应用第二次笔记
查看>>
Django之ORM查询
查看>>
学习python第七天
查看>>
Flask基础(07)-->正则自定义转换器
查看>>
C++著名程序库的比较和学习经验(STL.Boost.GUI.XML.网络等等)
查看>>