C#多维数组学习使用
程序员文章站
2023-12-03 15:48:46
复制代码 代码如下: string[, ,] items = new string[,,] { { { "a1", "a2", "a3", "☆", "○" }, { "b...
复制代码 代码如下:
string[, ,] items =
new string[,,] {
{
{ "a1", "a2", "a3", "☆", "○" },
{ "b1", "b2", "b3", "☆", "○" },
{ "c1", "c2", "c3", "☆", "○" },
{ "d1", "d2", "d3", "☆", "○" }
}, {
{ "e1", "e2", "e3", "☆", "○" },
{ "f1", "f2", "f3", "☆", "○" },
{ "g1", "g2", "g3", "☆", "○" },
{ "h1", "h2", "h3", "☆", "○" }
}
};
代码:
复制代码 代码如下:
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]);
运行结果如下:
复制代码 代码如下:
items.rank =3
items.getupperbound(0)=1
items.getupperbound(1)=3
items.getupperbound(2)=4
items[0, 0, 0]=a1
items[0, 0, 1]=a2
items[0, 0, 2]=a3
items[0, 0, 3]=☆
items[0, 0, 4]=○
items[0, 1, 0]=b1
items[0, 2, 0]=b2
items[0, 2, 0]=b3
items[0, 2, 0]=☆
items[0, 2, 0]=○
其中:
getupperbound(0) 返回数组的第一维的索引上限,getupperbound(i)返回数组的i+1维的上限,getupperbound(rank-1)返回数组的最后一维的上限,也就是列数-1