Declare and fill a two-dimensional array in C#

int[, ] my2DArray = { { 1, 1 }, { 3, 5 }, { 5, 7 } }; 
for (int i = 0; i <= my2DArray. GetUpperBound(0) ; i++) 
{ 
     for (int x = 0; x <= my2DArray.GetUpperBound(1); x++) 
     { 
          Console.WriteLine("Index = [{0},{1}]  Value = {2}", i, x, my2DArray[i, x] ); 
     } 
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.