Giả sử mảng ba chiều của chúng ta là -
int[,,] arr = new int[3,4,5];
Để lấy chiều cao và chiều rộng, tức là các hàng và cột.
Array.GetLength(0) – for rows Array.GetLength(1) – for columns
Ví dụ
using System;
class Program {
static void Main() {
int[,,] arr = new int[3,4,5];
Console.WriteLine(arr.GetLength(0));
Console.WriteLine(arr.GetLength(1));
Console.WriteLine(arr.GetLength(2));
}
} Đầu ra
3 4 5