Hi there, i can initialize a two dimensional array:
- int[,] myDimensional2 = new int[2, 3] { { 10, 20, 30 }, { 40, 50, 60} };
but i don't know how i can initialize a three, four,... dimensional arrays? :(
please initialize this array and give me the code, thank you so much :)
- int[,,] threeDimensional = new int[2, 2, 3];

Brajesh KumarRank #678 · 3.5K reputationPosted Mar 2, 2017, 4:27 AM EST
The array in your question has only one element, so you only need one value to completely initialise it. You need three sets of braces, one for each dimension of the array.
A clearer example might be:
As you can see, there are two groups, each containing three groups of 4 numbers.
intarr[3][3][3]={{{11, 12, 13},{14, 15, 16},{17, 18, 19}},{{21, 22, 23},{24, 25, 26},{27, 28, 29}},{{31, 32, 33},{34, 35, 36},{37, 38, 39}},};Nilesh ShahRank #42 · 34.2K reputationPosted Mar 2, 2017, 4:36 AM EST
Nilesh ShahRank #42 · 34.2K reputationPosted Mar 2, 2017, 5:02 AM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts