C# 如何查看來源程式的IL代碼

來源:互聯網
上載者:User

標籤:des   http   檔案   os   cti   for   

 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代碼:

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.