Declare, create, and initialize the rectangular array : Multi Dimensional Array : Data Structure C# Examples


C# Examples » Data Structure » Multi Dimensional Array »

 

Declare, create, and initialize the rectangular array





The general form of a multidimensional array declaration:




    
type[,  ...,]  name  =  new  type[size1,  size2,  ...,  sizeN];
    
   
  
   

The general form of array initialization for a two-dimensional array is shown here:




    
type[,]  array_name  =  {
{  val,  val,  val,  ...,  val  },
{  val,  val,  val,  ...,  val  },
.
.
.
{  val,  val,  val,  ...,  val  }
};
    
   
  
   





    
using  System;

class  MainClass
{
      static  void  Main()
      {
            int[,]  arr  =  new  int[2,  3]  {  {  0,  1,  2  },  {  10,  11,  12  }  };

            for  (int  i  =  0;  i  <  2;  i++){
                  for  (int  j  =  0;  j  <  3;  j++){
                        Console.WriteLine(arr[i,  j]);                  
                  }
            }
      }
}
    
   
  
   



Output

0
1
2
10
11
12


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Multi Dimensional Array