C#多維陣列學習使用

來源:互聯網
上載者:User

複製代碼 代碼如下: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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.