C# Multidimensional Array
Syntax
datatype[,] arrayName = new datatype[x,y];
Example
int[,] myArray = new int[3,3] {{1,2,3}, {4,5,6}, {7,8,9}};
Output
1 2 3
4 5 6
7 8 9
Explanation
A multidimensional array in C# is an array that has more than one dimension. It is declared using square brackets "[ ]" and a comma separator. The first bracket indicates the number of rows and the second bracket indicates the number of columns.
To create a multidimensional array in C#, you need to specify the data type, the array name, and the dimensions in square brackets. Here "x" and "y" indicate the number of rows and columns respectively.
In the example above, an integer multidimensional array with dimensions 3x3 (3 rows and 3 columns) is declared and initialized with values.
To access the elements of a multidimensional array, simply use the index of each dimension separated by a comma.
Use
Multidimensional arrays allow developers to store and manipulate large amounts of data in a structured way. They are commonly used in many programming applications, such as data processing, image processing, and scientific computing.
Important Points
- In C#, a multidimensional array is declared using square brackets "[ ]" and a comma separator.
- The first bracket indicates the number of rows and the second bracket indicates the number of columns.
- To access the elements of a multidimensional array, simply use the index of each dimension separated by a comma.
Summary
A multidimensional array is a powerful data structure that allows you to store and manipulate large amounts of data in a structured way. It is declared using square brackets and a comma separator, and the first bracket indicates the number of rows and the second bracket indicates the number of columns. Multidimensional arrays are commonly used in many programming applications, such as data processing and scientific computing.