如何在 C# 中对数组进行排序?
csharpprogrammingserver side programming更新于 2025/7/10 18:22:17
以下是整数数组。
int[] arr = { 99, 43, 86 };
要排序,请使用 Sort() 方法。
Array.Sort(arr);
以下是完整的代码,展示了如何在 C# 中使用 Sort() 方法对数组进行排序。
示例
using System;
class Demo {
static void Main() {
int[] arr = { 99, 43, 86 };
// 排序
Array.Sort(arr);
Console.WriteLine("已排序列表");
foreach (int res in arr) {
Console.Write("
"+res);
}
Console.WriteLine();
}
}
输出
已排序列表 43 86 99

