Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Kích thước mảng ba chiều (Three-dimensional array) trong C#


Để lấy kích thước mảng 3D trong C#, dùng phương thức GetLength() với tham số là chỉ mục chiều.

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]; 
        // chiều dài của một chiều 
        Console.WriteLine(arr.GetLength(0)); 
        Console.WriteLine(arr.GetLength(1)); 
        Console.WriteLine(arr.GetLength(2)); 
        // tổng độ dài 
        Console.WriteLine(arr.Length); 
    } 
}

Kết quả

3 
4 
5 
60