Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用第一个维度将所有第二个维度的数组值传递给另一个数组_C#_Arrays_Multidimensional Array - Fatal编程技术网

C# 使用第一个维度将所有第二个维度的数组值传递给另一个数组

C# 使用第一个维度将所有第二个维度的数组值传递给另一个数组,c#,arrays,multidimensional-array,C#,Arrays,Multidimensional Array,这些问题可能有点让人困惑,对此我感到非常抱歉 所以。。假设我有2个二维数组 int[,] first = new int[2,3]; int[,] second = new int[2,3] { { 1, 1, 1 }, { 4, 3, 1 } }; 现在我要做的是将第二个数组的所有内容复制到第一个数组中 也许是这样的 first[] = second[]; 如果不使用for并逐个传递值,这是否可行?您可以使用数组。按如下方式复制: int[,] first = new int[2, 3];

这些问题可能有点让人困惑,对此我感到非常抱歉

所以。。假设我有2个二维数组

int[,] first = new int[2,3];
int[,] second = new int[2,3] { { 1, 1, 1 }, { 4, 3, 1 } };
现在我要做的是将第二个数组的所有内容复制到第一个数组中

也许是这样的

first[] = second[];
如果不使用for并逐个传递值,这是否可行?

您可以使用数组。按如下方式复制:

int[,] first = new int[2, 3];
int[,] second = new int[2, 3] { { 1, 1, 1 }, { 4, 3, 1 } };

Array.Copy(second, first, second.Length);

如果要使用first=second;,它将传递对它的引用。因此,如果更改第二个数组上的值,它也会更改第一个数组上的值。所以,Array.Copy就是您想要的。

目前正在尝试,但我仍然不清楚第三个参数的长度是什么?是要复制多少数组元素的长度还是。。。什么?@Nathanelaldo是的,这是你要复制多少元素的长度。但是你的IDE应该已经告诉你了。@Nathanelaldo如果我的答案有帮助,你应该把它标记为正确的,这样其他人也会知道。不是我没有标记你的答案,而是我的声誉低于15,所以公众不会看到它,谢谢@sLw