C#多維數(shù)組學習使用
更新時間:2012年09月21日 08:30:50 作者:
當下, 由于存儲結構需要, 用多維數(shù)組, 順便學習了一下, 將學習經(jīng)過備忘如下
復制代碼 代碼如下:
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) 返回數(shù)組的第一維的索引上限,GetUpperBound(i)返回數(shù)組的i+1維的上限,GetUpperBound(Rank-1)返回數(shù)組的最后一維的上限,也就是列數(shù)-1
相關文章
舊項目升級新版Unity2021導致Visual?Studio無法使用的問題
在項目開發(fā)過程中,不可避免的會升級開發(fā)工具。這次我在舊項目版本升級到新版Unity2021.2.x時,出現(xiàn)Visual?Studio無法定位等問題,這里我給大家分享下解決方法,舊項目升級新版Unity2021導致Visual?Studio無法使用的問題,需要的朋友可以參考下2021-12-12C#控制臺基礎 List泛型集合與對應的數(shù)組相互轉換實現(xiàn)代碼
這篇文章主要介紹了C#控制臺基礎 List泛型集合與對應的數(shù)組相互轉換實現(xiàn)代碼,需要的朋友可以參考下2016-12-12