哈希表和Dictionary泛型的循环方式


HashTable ht = new HashTable();

foreach(DictionaryEntry xx in ht)

{

     Response.Write(xx.Key);  

     Response.Write(xx.Value);

}

 

有了泛型字典我们就可以这样用

 

Dictionary<string,string> dt = new Dictionary<string,string>();

foreach(KeyValuePair<string,string> xx in dt)

{

     Response.Write(xx.Key);  

     Response.Write(xx.Value);

}

 

虽然功能差不多,但Dictionary 继承了IEnumerator接口,提供了更多泛型特有的方法给我们用,具体的大家用Reflector反编译一下看下源代码了

posted @ 2011-11-14 10:32  振乾  阅读(202)  评论(0)    收藏  举报