คุณสมบัติ Values ได้รับ ICollection ที่มีค่าใน Hashtable
ประกาศคอลเลกชัน Hashtable -
Hashtable ht = new Hashtable();
ตอนนี้เพิ่มค่า
ht.Add("One", "Henry");
ht.Add("Two", "Kevin");
ht.Add("Three", "David"); เพื่อแสดงค่าจาก Hashtable ต่อไปนี้เป็นรหัส -
ตัวอย่าง
using System;
using System.Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
Hashtable ht = new Hashtable();
ht.Add("One", "Henry");
ht.Add("Two", "Kevin");
ht.Add("Three", "David");
// Displaying values
foreach (string value in ht.Values) {
Console.WriteLine(value);
}
Console.ReadKey();
}
}
} ผลลัพธ์
David Henry Kevin