简体   繁体   中英

How to declare and instantiate a matrix of arrays

I am trying to Instantiate a matrix that contains arrays of colors. But I am doing something wrong.

Color[][,] map_clrs = new Color[64][ 8, 8 ];

I would like to end up with the following data structure. I put Color[] first because I assumed it would be the same as when you do it with an int[,]

{
 { Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64] },
 { Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64] },
 { Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64] },
 { Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64] },
 { Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64] },
 { Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64] },
 { Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64] },
 { Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64], Color[64] }
}

ANSWER: is this correct?

Color[,][] map_clrs = new Color[8,8][];
Color[][,] map_clrs = new Color[64][,];
for(var i = 0;i<64;i++)
{
    map_clrs[i] = new Color[8,8];
}

And for the inverse:

Color[,][] map_clrs = new Color[8,8][];
for(var i = 0;i<8;i++)
{ 
    for (var j=0;j<8;j++)
    {
         map_clrs[i,j] = new Color[64];
    }
}

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