您的位置:首页 > 其它

不同类型数组排序

2012-03-31 15:02 127 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: