Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.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#_.net_Arrays_Multidimensional Array - Fatal编程技术网

维度中的C#元素

维度中的C#元素,c#,.net,arrays,multidimensional-array,C#,.net,Arrays,Multidimensional Array,我想使用C#找出所提供维度中的元素数: int[][]不是一个多维数组-它的交错数组(即,它是数组的数组)。若要在某个索引处获取数组的长度,应使用 arr[0].Length 但在获取数组元素的长度之前,请确保已初始化该元素(否则将获得NullReferenceException)。例如: 您还可以使用数组初始值设定项语法初始化交错数组: int[][] arr = { new[] { 1, 2, 3 }, new[] { 4, 5 }, new[] { 6 } }; 请注意,多维数组定义为

我想使用C#找出所提供维度中的元素数:


int[][]
不是一个多维数组-它的交错数组(即,它是数组的数组)。若要在某个索引处获取数组的长度,应使用

arr[0].Length
但在获取数组元素的长度之前,请确保已初始化该元素(否则将获得NullReferenceException)。例如:

您还可以使用数组初始值设定项语法初始化交错数组:

int[][] arr = { new[] { 1, 2, 3 }, new[] { 4, 5 }, new[] { 6 } };
请注意,多维数组定义为
int[,]
。您可以使用
GetLowerBound(int-dimension)
(通常为零)和
GetUpperBound(int-dimension)
来获取每个数组维度的边界。例如,创建大小为2 x 4的多维数组:

int[,] grid = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } };
grid.GetUpperBound(0);  // 1
grid.GetUpperBound(1);  // 3

进一步阅读:和

谢谢,刚刚理解我的问题有多愚蠢)@Src没有愚蠢的问题:)
int[][] arr = { new[] { 1, 2, 3 }, new[] { 4, 5 }, new[] { 6 } };
int[,] grid = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } };
grid.GetUpperBound(0);  // 1
grid.GetUpperBound(1);  // 3