要获取三维数组的边界,请使用GetUpperBound()
GetLowerBound()
C#中的方法。
这些方法下要设置的参数是尺寸,即
假设我们的数组是-
int[,,] arr = new int[3,4,5];
对于三维数组,维数为0。
arr.GetUpperBound(0) arr.GetLowerBound(0)
对于三维数组,维为1。
arr.GetUpperBound(1) arr.GetLowerBound(1)
对于三维数组,维2。
arr.GetUpperBound(2) arr.GetLowerBound(2)
让我们看看整个例子。
using System; class Program { static void Main() { int[,,] arr = new int[3,4,5]; Console.WriteLine("Dimension 0 Upper Bound: {0}",arr.GetUpperBound(0).ToString()); Console.WriteLine("Dimension 0 Lower Bound: {0}",arr.GetLowerBound(0).ToString()); Console.WriteLine("Dimension 1 Upper Bound: {0}",arr.GetUpperBound(1).ToString()); Console.WriteLine("Dimension 1 Lower Bound: {0}",arr.GetLowerBound(1).ToString()); Console.WriteLine("Dimension 2 Upper Bound: {0}",arr.GetUpperBound(2).ToString()); Console.WriteLine("Dimension 2 Lower Bound: {0}",arr.GetLowerBound(2).ToString()); } }
输出结果
Dimension 0 Upper Bound: 2 Dimension 0 Lower Bound: 0 Dimension 1 Upper Bound: 3 Dimension 1 Lower Bound: 0 Dimension 2 Upper Bound: 4 Dimension 2 Lower Bound: 0