Để nhận kích thước của mảng 3D trong C #, hãy sử dụng phương thức GetLength () với tham số là chỉ số của kích thước.
GetLength(dimensionIndex)
Để lấy kích thước.
arr.GetLength(0) arr.GetLength(1) arr.GetLength(2)
Ví dụ
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);
}
} Đầu ra
3 4 5 60