我可以在2D阵列中存储一维数组吗?

时间:2021-06-10 21:18:14

How can I store an array into a 2d array. To explain what I mean I'll use numbers.

如何将数组存储到二维数组中。要解释我的意思,我会使用数字。

a1dArray = 1,2,3
another1dArray = 4,5,6
a2dArray[1] = a1dArray
a2dArray[2] = another1dArray

Result:

a2dArray[1,0] = 1
a2dArray[1,1] = 2
a2dArray[1,2] = 3
a2dArray[2,0] = 4
a2dArray[2,1] = 5
a2dArray[2,3] = 6

Here is how I want to do it in my code animations is the 2d array and the function returns a 1d array

以下是我想在代码中执行的操作动画是2d数组,函数返回1d数组

Animation [index] animations = part.FindModelAnimators(animationName)

1 个解决方案

#1


Declare a2dArray as int[n][] rather than int[n, m]. (n and m are any integers you care to use as the length of your array.) You'll then be able to jam an entire int[] array into it, just like in your example. Read more on jagged arrays at MSDN.

将a2dArray声明为int [n] []而不是int [n,m]。 (n和m是你想要用作数组长度的任何整数。)然后你就可以将整个int []数组插入其中,就像在你的例子中一样。在MSDN上阅读有关锯齿状阵列的更多信息。

Reading from the array will then be done like int oneVal = a2dArray[n][m].

然后将从int oneVal = a2dArray [n] [m]中读取数组。

#1


Declare a2dArray as int[n][] rather than int[n, m]. (n and m are any integers you care to use as the length of your array.) You'll then be able to jam an entire int[] array into it, just like in your example. Read more on jagged arrays at MSDN.

将a2dArray声明为int [n] []而不是int [n,m]。 (n和m是你想要用作数组长度的任何整数。)然后你就可以将整个int []数组插入其中,就像在你的例子中一样。在MSDN上阅读有关锯齿状阵列的更多信息。

Reading from the array will then be done like int oneVal = a2dArray[n][m].

然后将从int oneVal = a2dArray [n] [m]中读取数组。