Thuộc tính Values lấy một ICollection chứa các giá trị trong Hashtable.
Khai báo Hashtable:
Hashtable ht = new Hashtable();
Thêm giá trị:
ht.Add("One", "Henry");
ht.Add("Two", "Kevin");
ht.Add("Three", "David");
Code hiển thị values từ Hashtable:
Ví dụ
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");
// Hiển thị values
foreach (string value in ht.Values) {
Console.WriteLine(value);
}
Console.ReadKey();
}
}
}
Kết quả
David
Henry
Kevin