C#中Hashtable类的Values属性是什么?
Values属性获取一个ICollection,其中包含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");
//显示值
foreach (string value in ht.Values) {
Console.WriteLine(value);
}
Console.ReadKey();
}
}
}输出结果
David Henry Kevin