double[,] matrix = new double[,] { {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} }; for (int i = 0; i < matrix.GetLength(0); i++) { double[] row = new double[matrix.GetLength(1)]; for (int j = 0; j < matrix.GetLength(1); j++) { row[j] = matrix[i, j]; } Console.WriteLine($"Row {i}: [{string.Join(", ", row)}]"); }
using System.Numerics; MatrixIn this example, we create a 3x3 matrix using the System.Numerics package library. We then retrieve all the rows of the matrix using the GetRows method and store them in an array of matrices. We then print out each row of the original matrix by iterating over this array of matrices.matrix = new Matrix (3, 3); matrix[0, 0] = 1.0f; matrix[0, 1] = 2.0f; matrix[0, 2] = 3.0f; matrix[1, 0] = 4.0f; matrix[1, 1] = 5.0f; matrix[1, 2] = 6.0f; matrix[2, 0] = 7.0f; matrix[2, 1] = 8.0f; matrix[2, 2] = 9.0f; Matrix [] rows = matrix.GetRows(); for (int i = 0; i < rows.Length; i++) { Console.WriteLine($"Row {i}: [{string.Join(", ", rows[i])}]"); }