ในการรับขนาดของอาร์เรย์ 3 มิติใน C# ให้ใช้เมธอด GetLength() โดยมีพารามิเตอร์เป็นดัชนีของมิติ
GetLength(dimensionIndex)
เพื่อให้ได้ขนาด
arr.GetLength(0) arr.GetLength(1) arr.GetLength(2)
ตัวอย่าง
using System;
class Program {
static void Main() {
int[,,] arr = new int[3,4,5];
// length of a dimension
Console.WriteLine(arr.GetLength(0));
Console.WriteLine(arr.GetLength(1));
Console.WriteLine(arr.GetLength(2));
// length
Console.WriteLine(arr.Length);
}
} ผลลัพธ์
3 4 5 60