C#中Hashtable的遍历办法
2014-01-24 10:14
190 查看
C#中Hashtable的遍历办法
C#中Hashtable的遍历办法System.Collections.Hashtable 是用来表示一组组key/value结构的容器,可能别的语言会把它叫做Map,Dictionary,其结构中Key用来快速查找,所以,叫它Dictionary可能更加合适。Hashtable的方法、属性并不多,大多数也可以望文生正义,只是有一点,Hashtable提供了hashTable[aKey]的方式引用其包含的对象,却并没有提供数字指向的索引器,就是说用惯了Array,数组的我们,不能用hashTable[0]之类的办法来检索它的内容,继而,我们也就不能用
for(int i =0 ; i < hashTable.count ; i ++)
{
Console.WriteLine("Key -- {0}; Value --{1}.",hashTable[i].key,hashTable[i].value);
}
这样的代码块来遍历,而我们把一个个的键值对加入HashTable中,很多情况下都是最终要把它遍历出来,那么怎么做呢?以下代码将解答这个问题。
foreach( DictionaryEntry de in hashTable)
{
console.WriteLine("Key -- {0}; Value --{1}.", de.Key, de.Value);
}
相关文章推荐
- setTimeout和setInterval的区别及用法、C#中遍历Hashtable对象[哈希表]的3种方法【遍历Hashtable】
- 在C#中怎样遍历Hashtable中的值
- C#中遍历Hashtable
- C#遍历HashTable
- c#遍历HashTable
- c#遍历HashTable
- [转载]C# HashTable 遍历与排序
- C# 遍历Hashtable
- 黄聪:C#使用能够foreach对hashtable、List遍历时“集合已修改;可能无法执行枚举操作。”错误
- c#hashtable 遍历
- C# 遍历HashTable
- C#中如何遍历Hashtable中的值
- C#遍历HashTable
- C#使用foreach遍历哈希表(hashtable)的方法
- c# hashTable的遍历【2种方法】与排序【3种方法】
- 如何在C#中遍历hashtable?
- C#遍历访问Dictionary和HashTable
- C#遍历访问Dictionary和HashTable
- C#中HashTable的遍历
- 黄聪:C#使用能够foreach对hashtable、List遍历时“集合已修改;可能无法执行枚举操作。”错误