不同类型数组排序

public class SortHelper<T> where T : IComparable
{
    public void BubbleSort(T[] array)
    {
        for (int i = 0; i < array.Length; i++)
        {
            for (int j = i + 1; j < array.Length; j++)
            {
                if (array[i].CompareTo(array[j]) < 0)
                {
                    T temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                }
            }
        }

    }

}

protected void Page_Load(object sender, EventArgs e)
    {
        SortHelper<int> sort = new SortHelper<int>();
        int[] array = { 4, 5, 3, 1, 2 };
        sort.BubbleSort(array);
        foreach (int item in array)
        {
            Response.Write(item + "<br/>");
        }
        Type t = typeof(int);
        Assembly asm = t.Assembly;       
    }

posted on 2012-03-31 15:02  李菲菲  阅读(183)  评论(0编辑  收藏  举报