如何声明和使用数组2维度

时间:2016-07-21 13:54:31

标签: c# multidimensional-array

我想这样做:

uint8_t **t;
int i;
int m[100];
int i;
t = calloc(n, sizeof(uint8*));
...
/* m is initialized in other function */
...
for (i=0;i<n;i++)
{
    /* m[i] is calculated here */        
    *t = calloc(1, sizeof(uint8)*m[i]);
}

我想转换此行为

byte [][]t;
int i;
int[] m = new int [100];
...
/* m is initialized in other function */
...
t = new byte[n];
for (i=0;i<n;i++)
{
    /* m[i] is calculated here */
    t[i] = new byte[m[i]]; 
}

这样做是否正确

1 个答案:

答案 0 :(得分:1)

列表可能适合您吗?然后你可以根据需要构建一个字节数组并添加到整个List集合对象中?

    List<byte[]> myByteList = new List<byte[]>();
    for (whatever loop )
    {
       byte[] justOne = however you build one byte array;

       myByteList.Add( justOne );
    }

然后你可以稍后迭代它......

foreach( byte[] oneByteArray in myByteList )
{
   do something with the oneByteArray;
}