Jagged array คืออาร์เรย์ของอาร์เรย์ใน C # คุณสามารถประกาศและเริ่มต้นได้ -
int[][] rank = new int[1][]{new int[]{5,3,1}}; ต่อไปนี้คือตัวอย่างที่แสดงวิธีการทำงานกับอาร์เรย์ที่มีรอยหยักใน C# -
ตัวอย่าง
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 อาร์เรย์ -
int[][] rank = new int[][]{new int[]{1,2},new int[]{3,4}};