Mảng số nguyên sau:
int[] arr = { 99, 43, 86 };
Để sắp xếp, dùng phương thức Sort():
Array.Sort(arr);
Ví dụ
using System;
class Demo {
static void Main() {
int[] arr = { 99, 43, 86 };
// sắp xếp
Array.Sort(arr);
Console.WriteLine("Danh sách đã sắp xếp");
foreach (int res in arr) {
Console.Write("\n" + res);
}
}
}
Kết quả
Danh sách đã sắp xếp 43 86 99