C# 中 Hashtable 类的 Values 属性是什么?
csharpprogrammingserver side programming更新于 2025/10/15 3:07:17
Values 属性获取一个包含 Hashtable 中值的 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

