C# Multidimensional Arrays

tutorial and example
tutorial and example

In C#, A multidimensional Array represents data storage in tabular form (in the form of matrix (rows and columns)). Number of dimensions is not fixed. It can be 2, 3 or n-dimensional.

In C#, it is also known as Rectangular arrays. Let’s see the declaration of 2D and 3D arrays.

int[,] arr=new int[3,3];//declaration of 3X3 array

int[,,] arr=new int[3,3,3]; //declaration of 3X3X3 array

C# Multidimensional array Example:

Output

1 2 3
4 5 6
7 8 9

C# Multidimensional Array Example: sum of 2 3X3 matrices

The following Example declare and initialize two 3X3 array and calculate sum of them.

Output

11 13 15
17 19 21
23 25 27