HashTable称为哈希表,和ArrayList不同的是它利用键/值来存储数据。
HashTable是System.Collections命名空间中的一个重要类
属性
count 获取包含在hashtable中的键值对的数目
keys 获取包含hashtable中所有键的集合
values 获取包含hashtable中所有值的集合
方法名称
add 将带有指定键和值的元素添加到hashtable中
clear 从hashtable中移除所有的元素
contains 确定hashtable是否包含特定键
getenumerator 返回IDictionaryEnumerator,可以遍历hashtable
remove 从hashtable中移除带有指定键的元素
实例
ICollection valueColl=openwith.values;//得到哈希表值的集合
foreach (string s in valueColl)
{
console.writeline("值={0}",s); //循环输出值
}
ICollection KeyColl=openwith,keys;
foreach(string s in KeyColl)
{
console.WriteLine("键={0}",s); //循环输出键
}