Thuộc tính Giá trị nhận được một ICollection chứa các giá trị trong Hashtable.
Khai báo bộ sưu tập Hashtable -
Hashtable ht = new Hashtable();
Bây giờ hãy thêm các giá trị
ht.Add("One", "Henry");
ht.Add("Two", "Kevin");
ht.Add("Three", "David"); Để hiển thị các giá trị từ Hashtable, sau đây là mã -
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");
// Displaying values
foreach (string value in ht.Values) {
Console.WriteLine(value);
}
Console.ReadKey();
}
}
} Đầu ra
David Henry Kevin