Initialize multidimensional arrays in declaration : Multi Dimensional Array : Data Structure C# Examples


C# Examples » Data Structure » Multi Dimensional Array »

 

Initialize multidimensional arrays in declaration









    
using  System;

class  MainClass
{
        public  static  void  Main()
        {
        int[,]  matrix  =  {  {1,  1},  {2,  2},  {3,  5},  {4,  5},  {134,  44}  };
                
                for  (int  i  =  0;  i  <  matrix.GetLength(0);  i++)
                {
                        for  (int  j  =  0;  j  <  matrix.GetLength(1);  j++)
                        {
                                Console.WriteLine("matrix[{0},  {1}]  =  {2}",  i,  j,  matrix[i,  j]);
                        }
                }        
        }
}
    
   
  
   



Output

matrix[0, 0] = 1
matrix[0, 1] = 1
matrix[1, 0] = 2
matrix[1, 1] = 2
matrix[2, 0] = 3
matrix[2, 1] = 5
matrix[3, 0] = 4
matrix[3, 1] = 5
matrix[4, 0] = 134
matrix[4, 1] = 44


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Multi Dimensional Array