简体   繁体   English

获取和设置大型多维数组特定部分的值

[英]Getting and setting the value of a specific part of a large multi-dimensional array

Say, I have an array FooArray, which consists of arrays consisting of arrays of arrays- etc. 说,我有一个数组FooArray,其中包含由数组等组成的数组。

Then I have another variable D, defining in which depth of the array I want to be looking at. 然后,我有另一个变量D,用于定义要查看的数组深度。

And lastly I have another array nArray of integers, which determine which array in each depth should be dug further into. 最后,我还有另一个整数数组nArray,它确定每个深度中的哪个数组应进一步挖掘。

(At least, that's the way I tried to approach this) (至少,这就是我尝试解决此问题的方式)

Now my question is, how would I get/set any index of the array at depth D, in FooArray? 现在我的问题是,如何在FooArray中获取/设置深度D处的数组的任何索引? For instance, the array may look like this: 例如,数组可能如下所示:

[FooArray]
 -- [Array]
     -- [Array]
         -- [Array]
         -- [Array]
     -- [Array] <--- With D = 1 and nArray = {0,1,...}, I'd want this array.
         -- [Array]
         -- [Array]
 -- [Array]
     -- [Array]
         -- [Array]
         -- [Array]
     -- [Array]
         -- [Array]
         -- [Array]

There's probably a way to do this, but how? 可能有一种方法可以做到,但是如何呢?

Thanks in advance! 提前致谢!

Probably you're better off using a multidimensional array : 也许您最好使用多维数组

int[, ,] a = new int[2, 2, 3]{
        { {1,2,3}, {4,5,6} },
        { {7,8,9}, {10,11,12}  }
};
int x = (int)a.GetValue(0,1,2); // this returns 6

int[] nArray = new int[] { 1, 1, 0 };
x = (int)a.GetValue(nArray); // this returns 10

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

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