简体   繁体   中英

Declare 3d array with dynamic 3th dimension in C#

I need to declare 3d array variable but can't.

int[][][]  ary = new int[5][2][];
ary[0,0] = new int[20];
ary[0,1] = new int[3];

Could you please help me!

Thanks in advance Hamid

int[,][] ary = new int[5,2][];

declares a 2D array of int[] objects and initializes it. Use

ary[0, 0] = new int[10];
ary[0, 0][0] = 42;

to access elements.

Note that in C#, multidimensional arrays are different from arrays of arrays. That is, int[][][] is a single dimensional array of single dimensional arrays of single dimensional arrays of integers while int[,,] is a three dimensional array of integers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM