开发者

How to create 2D jagged array

开发者 https://www.devze.com 2022-12-25 20:24 出处:网络
In my code an array is declared as follows private Object[,] cellInfos = new Object[20, 10]; I need to convert it into Jagged array so I wrote following code

In my code an array is declared as follows

private Object[,] cellInfos = new Object[20, 10];

I need to convert it into Jagged array so I wrote following code

private Object[][] cellInfos = {
    new Object[20],
    new Object[10]
};

But it gave me a array with 2 items each of type 开发者_高级运维array.

I need to create 2D array where new Object[20] would be first column and new Object[10] would be the second one.


I think you want something more like this:

object[][] cellInfos = new object[20][];
for (int i = 0; i < cellInfos.Length; i++)
{
   cellInfos[i] = new object[10];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消