jrliv
6/1/2017 - 10:53 PM

Example of how to create, initialize, and print a multidimensional array also called matrices. From Fundamentals of Computer Programming wit

Example of how to create, initialize, and print a multidimensional array also called matrices. From Fundamentals of Computer Programming with C# http://www.introprogramming.info/wp-content/uploads/2013/07/Books/CSharpEn/Fundamentals-of-Computer-Programming-with-CSharp-Nakov-eBook-v2013.pdf

// Declare and initialize a matrix of size 2 x 4
int[,] matrix =
{
  {1, 2, 3, 4}, // row 0 values
  {5, 6, 7, 8}, // row 1 value
};

// Print the matrix on the console
for (int row = 0; row < matrix.GetLength(0); row++)
{
  for (int col = 0; col < matrix.GetLength(1); col++)
  {
    Console.Write(matrix[row, col]);
  }
  Console.WriteLine();
}

//  1 2 3 4
//  5 6 7 8