c#多维数组的一个小例子,供大家学习参考。
1、数组:
2、代码:
System.Console.WriteLine("Items.Rank =" + items.Rank);
System.Console.WriteLine("Items.GetUpperBound(0)=" + items.GetUpperBound(0));
System.Console.WriteLine("Items.GetUpperBound(1)=" + items.GetUpperBound(1));
System.Console.WriteLine("Items.GetUpperBound(2)=" + thirdItems.GetUpperBound(items.Rank - 1));
System.Console.WriteLine("Items[0, 0, 0]=" + items[0, 0, 0]);
System.Console.WriteLine("Items[0, 0, 1]=" + items[0, 0, 1]);
System.Console.WriteLine("Items[0, 0, 2]=" + items[0, 0, 2]);
System.Console.WriteLine("Items[0, 0, 3]=" + items[0, 0, 3]);
System.Console.WriteLine("Items[0, 0, 4]=" + items[0, 0, 4]);
System.Console.WriteLine("Items[0, 1, 0]=" + items[0, 1, 0]);
System.Console.WriteLine("Items[0, 2, 0]=" + items[0, 1, 1]);
System.Console.WriteLine("Items[0, 2, 0]=" + items[0, 1, 2]);
System.Console.WriteLine("Items[0, 2, 0]=" + items[0, 1, 3]);
System.Console.WriteLine("Items[0, 2, 0]=" + items[0, 1, 4]);
3、输出结果:
说明:
GetUpperBound(0) 返回数组的第一维的索引上限
GetUpperBound(i)返回数组的i+1维的上限
GetUpperBound(Rank-1)返回数组的最后一维的上限,也就是列数-1
例子比较简单,适合初学的朋友,了解c#多维数组的简单用法。