CSharp - Read Multidimensional Arrays from console window

Introduction

Here we are going to create a matrix with our preferred dimensions.

We have printed the output in a proper matrix form for better readability.

In the following example, each row has an equal number of columns (three), so it is a rectangular two-dimensional (2D) array.

Demo

using System;

class Program//from  ww  w  .j a va2 s .c  o m
{
    static void Main(string[] args)
    {
        Console.WriteLine("Enter how many rows you want?");
        String rowSize = Console.ReadLine();
        int row = int.Parse(rowSize);
        Console.WriteLine("Enter how many columns you want?");
        String columnSize = Console.ReadLine();
        int column = int.Parse(columnSize);
        int[,] myArray = new int[row, column];
        Console.WriteLine("Enter Data");
        for (int i = 0; i < row; i++)
        {
            for (int j = 0; j < column; j++)
            {
                myArray[i, j] = int.Parse(Console.ReadLine());
            }
        }
        //Printing the matrix
        Console.WriteLine("Your matrix is as below:");
        for (int i = 0; i < row; i++)
        {
            for (int j = 0; j < column; j++)
            {
                Console.Write(myArray[i, j] + "\t");
            }
        }
    }
}

Result