
交錯陣列是 C# 中的陣列的陣列。您可以宣告並初始化它-
1 | int[][] rank = new int[1][]{ new int[]{5,3,1}};
|
登入後複製
以下範例展示如何在C# 中使用鋸齒狀陣列-
範例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | using System;
namespace Program {
class Demo {
static void Main(string[] args) {
int[][] rank = new int[][]{ new int[]{1,2}, new int[]{3,4}};
int i, j;
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
Console.WriteLine( "a[{0}][{1}] = {2}" , i, j, rank[i][j]);
}
}
Console.ReadKey();
}
}
}
|
登入後複製
輸出
##上面,我們有一個由2 個整數陣列組成的鋸齒狀陣列-
1 | int[][] rank = new int[][]{ new int[]{1,2}, new int[]{3,4}};
|
登入後複製
以上是C# 中的鋸齒數組是什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!