Use the GetLength() method to get number of elements in each dimension of the two dimensional array : Array Length : Data Structure C# Examples


C# Examples » Data Structure » Array Length »

 

Use the GetLength() method to get number of elements in each dimension of the two dimensional array









    
using  System;

class  MainClass
{

    public  static  void  Main()
    {
        string[,]  names  =  {
            {"J",  "M",  "P"},
            {"S",  "E",  "S"},
            {"C",  "A",  "W"},
            {"G",  "P",  "J"},
        };

        int  numberOfRows  =  names.GetLength(0);
        int  numberOfColumns  =  names.GetLength(1);
        Console.WriteLine("Number  of  rows  =  "  +  numberOfRows);
        Console.WriteLine("Number  of  columns  =  "  +  numberOfColumns);

    }
}
    
   
  
   



Output

Number of rows = 4
Number of columns = 3


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Array Length