测试效率可以使用Stopwatch :
Stopwatch sw = new Stopwatch();
sw.Start();//写在要执行的代码前面sw.Stop();//写在要执行的代码结尾
sw.Elapsed//得到代码执行时间
int[] array = { 15,20,10,3,5};
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < array.Length-1; i++)
{
for (int j = i + 1; j < array.Length; j++)
{
if(array[i]>array[j]){
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
sw.Stop();
Console.WriteLine(sw.Elapsed);