using System;
class MainClass
{
static void Main()
{
// 2次元配列のベースとなるサイズ3の配列を定義
int [] [,] a = new int [3] [,];
// 2次元配列を定義して代入
a[0] = new int[,] { { 1, 2 }, { 3, 4 } };
a[1] = new int[,] { { 5, 6, 7 }, { 8, 9, 10 } };
a[2] = new int[,] { { 11, 12, 13, 14 }, { 15, 16, 17, 18 } };
// 配列の参照
// 出力値:1
Console.WriteLine(a[0][0, 0]);
// 出力値:9
Console.WriteLine(a[1][1, 1]);
// 出力値:18
Console.WriteLine(a[2][1, 3]);
// ベースとなる配列のサイズを表示
// 出力値:3
Console.WriteLine(a.Length);
// サブ配列(a[2])のサイズを表示
// 出力値:8
Console.WriteLine(a[2].Length);
// ベース配列、サブ配列(a[1])の次元数を表示
// 出力値:1
Console.WriteLine(a.Rank);
// 出力値:2
Console.WriteLine(a[1].Rank);
}
}
0 コメント:
コメントを投稿