简体   繁体   English

如何声明多维数组

[英]How to declare a multi-multi- dimensional array

Sounds simple and it probably is. 听起来很简单,也许是。

I have this variable: 我有这个变量:

byte[,,] data = new byte[360,288]

And I want 4 for them. 我想要4个给他们。

I do not want this though: 我不希望这样:

byte[,,,] data = new byte[360,288,4]

I prefer this: 我更喜欢这样:

byte[,,][] data = new byte[360,288][4]

Is it possible? 可能吗?

Yes this is a special case of jagged arrays, one where one of the jagged dimension is multidimensional. 是的,这是锯齿状数组的一种特殊情况,其中锯齿状维之一是多维的。

You should write something like this: 您应该这样写:

        // Initialise 4 arrays of two dimensional arrays
        byte[][,] data = new byte[4][,];
        // Initialise the arrays
        for (var i = data.GetLowerBound(0); i <= data.GetLowerBound(0); ++i)
            data[i] = new byte[360, 258];

Of course you can invert the dimensions if you need it. 当然,如果需要,您可以反转尺寸。

        // Initialise 4 arrays of two dimensional arrays
        byte[,][] data2 = new byte[360,258][];
        // Initialise the arrays
        for (var i = data2.GetLowerBound(0); i <= data2.GetLowerBound(0); ++i)
            for (var j = data2.GetLowerBound(1); j <= data2.GetLowerBound(1); ++j)
                data2[i,j] = new byte[4];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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