คลาส Array เป็นคลาสฐานสำหรับอาร์เรย์ทุกตัวใน C# อยู่ในเนมสเปซ System มีคุณสมบัติหลักดังนี้:
| No. | Property & Description |
|---|---|
| 1 | IsFixedSize - อาร์เรย์มีขนาดคงที่หรือไม่ |
| 2 | IsReadOnly - อาร์เรย์เป็น read-only หรือไม่ |
| 3 | Length - จำนวนสมาชิกทั้งหมด (32-bit) |
| 4 | LongLength - จำนวนสมาชิกทั้งหมด (64-bit) |
| 5 | Rank - จำนวนมิติ (rank) ของอาร์เรย์ |
ตัวอย่าง: ใช้ Array.Sort() เรียงลำดับ
using System;
namespace Demo {
class MyArray {
static void Main(string[] args) {
int[] list = { 45, 19, 9, 28, 87 };
int[] temp = list;
Console.Write("Original Array: ");
foreach (int i in list) Console.Write(i + " ");
Console.WriteLine();
Array.Sort(list);
Console.Write("Sorted Array: ");
foreach (int i in list) Console.Write(i + " ");
Console.WriteLine();
Console.ReadKey();
}
}
}
ผลลัพธ์
Original Array: 45 19 9 28 87 Sorted Array: 9 19 28 45 87