哈希表和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反编译一下看下源代码了
浙公网安备 33010602011771号