如何在 C# 中對陣列進行排序?
以下是整數陣列。
int[] arr = { 99, 43, 86 };要進行排序,請使用 Sort() 方法。
Array.Sort(arr);
以下是完整程式碼,演示如何在 C# 中使用 Sort() 方法對陣列進行排序。
示例
using System;
class Demo {
static void Main() {
int[] arr = { 99, 43, 86 };
// sort
Array.Sort(arr);
Console.WriteLine("Sorted List");
foreach (int res in arr) {
Console.Write("
"+res);
}
Console.WriteLine();
}
}輸出
Sorted List 43 86 99
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP