Generic List
เรามาดูตัวอย่างกัน −
เราได้กำหนดรายการไว้ก่อน -
List<string> myList = new List<string>()
ตอนนี้เพิ่มองค์ประกอบในรายการ -
List<string> myList = new List<string>() {
"mammals",
"reptiles",
"amphibians"
} ตอนนี้ใช้คุณสมบัติให้เรานับจำนวนขององค์ประกอบที่เพิ่ม -
ตัวอย่าง
using System;
using System.Collections.Generic;
class Program {
static void Main() {
List<string> myList = new List() {
"mammals",
"reptiles",
"amphibians"
};
Console.WriteLine(myList.Count);
}
}