Get the width and height of a three-dimensional array

CsharpProgrammingServer Side Programming

Let’s say our three-dimensional array is −

int[,,] arr = new int[3,4,5];

To get the height and width i.e. the rows and columns.

Array.GetLength(0) – for rows
Array.GetLength(1) – for columns

Example

 Live Demo

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));
   }
}

Output

3
4
5
raja
Published on 14-Sep-2018 16:16:08
Advertisements