首先,设置未排序的数组。int[] list = {98, 23, 97, 36, 77};
使用Sort()方法对数组进行排序。Array.Sort(list);
您可以尝试运行以下代码来对数组进行升序排序。
示例using System;
namespace Demo {
public class MyApplication {
public static void Main(string[] args) {
int[] list = {98, 23, 97, 36, 77};
Console.WriteLine("Original Unsorted List");
foreach (int i in list) {
Console.Write(i + " ");
}
Array.Sort(list);
Console.WriteLine("\nSorted List");
for(int i=0; i
Console.Write(list[i] + " ");
}
}
}
}
输出结果Original Unsorted List
98 23 97 36 77
Sorted List
23 36 77 97 98