Member-only story

Multidimensional Array in C#

Shahzad Aslam
6 min readMay 9, 2024

--

If you have date in the shape of tables, matrices, grids then multidimensional arrays are useful. We declared the multidimensional array by adding commas in the square brackets. We can declare two-dimensional, three-dimensional, four-dimensional array in such a way respectively [,], [, ,], [, , ,].

Multidimensional Array in C#

Features with variable in C#:

One Dimensional Array Declaration:

A One Dimensional can be declared by following sytax below.

One Dimensional Array Declaration : Example

dataType[] arrayName;
// Declare an integer array named NumIntArray
int[] NumIntArray;
// Declare a double array named NumDoubleArray
double[] NumDoubleArray;
// Declare a string array named NumStringArray
string[] NumStringArray;

Two Dimensional Array Declaration:

A Two Dimensional can be declared by following sytax below.

Two Dimensional Array Declaration : Example

dataType[,] arrayName;
// Later in code, initialize the array with specific values
arrayName = new dataType[rowCount, columnCount];
// A 2D-Array can be declare in following syntax
int[,] 2DIntNumArray = {
{21, 22},
{23, 24},
{25, 26}
};

Three Dimensional Array…

--

--

Shahzad Aslam
Shahzad Aslam

Written by Shahzad Aslam

Welcome to c-sharptutorial.com. I am Shahzad Aslam. I am the founder of c-sharptutorial.com. I'm currently living near Islamabad, Pakistan.

No responses yet