In C# arrays can have multiple dimensions, arrays with more than one dimension. C# can support nearly 32 dimensions for multidimensional arrays.
To declare a multidimensional array, use commas between the square brackets to delimit the array’s dimensions. Arrays can be classified according to their dimensions.
The dimension of an array can be identified by counting the commas. The number of commas in a multidimensional array equals one less than the number of dimensions. For example [,] is a 2D array, [, ,] is a 3D array, [, , ,] is a 4D array, so on and so forth.
C# 3D Array Examples
See the examples of C# 3D Array
//3D Array C#, Three-dimensional array in C#
int[, ,] Csharp3dArray = new int[,,] { { { 20, 25, 30 }, { 30, 35, 40 } },
{ { 7, 8, 9 }, { 10, 11, 12 } } };
//C# 3d array with dimensions specified.
int[, ,] 3dArrayCsharp = new int[2,2,3] { { { 20, 25, 30 },
{ 30, 35, 40 } },{ { 7, 8, 9 }, { 10, 11, 12 } } };
More Examples of C# 3d Arrays below..
C# 3d array with 1 row, 2-dimensional array [2,3]
int[, ,] 3darray1 = new int[1, 2, 3]{
{ { 4, 5,6}, { 3, 4,5} } };
C# 3d array with 2 row, 2 dimensional array [3,2]
int[, ,] 3darray2 = new int[2, 3, 2]{
{ {1, 2}, {3, 4} },
{ {5, 6}, {7, 8} },
{ {5, 6}, {7, 8} }
};
C# 3d array with 2 rows, 2-dimensional array [2,3]
int[, ,] 3darray3 = new int[2, 2, 3]{
{ { 1, 2, 3}, {4, 5, 6} },
{ { 7, 8, 9}, {10, 11, 12} }
};
C# 3d array with 3 rows of 2 diamensional array [3,3]
int[, ,] 3darray3 = new int[3, 3, 3]{
{ { 1, 2, 3}, {4, 5, 6}, {4, 5, 6}},
{ { 7, 8, 9}, {10, 11, 12}, {15, 16, 17}},
{ { 7, 8, 9}, {20, 21, 22},{30, 31, 32} }
};
The first rank gives the indication of the number of rows of the internal 2D arrays.
Summary
In this post, we explained C# 3d arrays and few examples. Hope this article was helpful for you. Please share your valuable feedback on 3d arrays in C# in the comments section
Leave a Reply