การกำหนดอาร์เรย์ใน C# −
int[] runs = new int[10];
ให้เราเริ่มต้นอาร์เรย์ในบรรทัดเดียวกัน -
int[] runs = new int[5] {99, 92, 95}; ต่อไปนี้คือตัวอย่างการแสดงวิธีการประกาศ เริ่มต้น และแสดงอาร์เรย์ −
ตัวอย่าง
using System;
namespace Program {
class Demo {
static void Main(string[] args) {
int[] runs = new int[3] {149, 123, 257};
int j;
for (j = 0; j < 3; j++ ) {
Console.WriteLine("Score of Cricketer[{0}] = {1}", j, runs[j]);
}
Console.ReadKey();
}
}
}