Saturday 15 September 2012

c# - nested array initializer is expected -



c# - nested array initializer is expected -

i'm trying create array holds 6 strings in 1 row, , many other rows after that. code:

string[, , , , , ,] conj = new string[,,,,,,] { {"aimer", "aime", "aimes", "aime", "aimons", "aimez", "aiment"}, };

i'm getting error "a nested array initializer expected". i've never made array big before, , couldn't find searching google why i'm getting error , need prepare this.

thanks help!

you trying initialize multi-dimensional rectangular array (7 dimensions!).

so...

// 1d array containing 2 elements: int[] r1d = { 1 , 2 , } ; // 2x3 array containing 6 elements: int[,] r2d = { { 1 , 2 , 3 , } , { 4 , 5 , 6 , } , } ; // 2x3x4 array int[,,] r3d = { { { 1 , 2 , 3 , 4 , } , { 5 , 6 , 7 , 8 , } , { 9 , 10 , 11 , 12 , } , } , { { 13 , 14 , 15 , 16 , } , { 17 , 18 , 19 , 20 , } , { 21 , 22 , 23 , 24 , } , } , } ;

one might see pattern developing here. should able take here (hint: you're going have curly braces nested 7 deep).

note each initializers must of same rank, lest compiler upset. instance, if say:

int[,,] r3d = { { { 1 , 2 , 3 , 4 , } , { 5 , 6 , 7 , 8 , } , { 9 , 10 , 11 , 12 , } , } , { { 13 , 14 , 15 , 16 , } , { 17 , 18 , 19 , 20 , } , //{ 21 , 22 , 23 , 24 , } , } , } ;

the compiler whines , says, an array initializer of length '3' expected. that's because initializer x3d[0,1] initializers inconsistent.

c# arrays visual-studio

No comments:

Post a Comment