日期:2014-05-17  浏览次数:20901 次

怎么将hashtable 强制转换成 dictionary
看到说 dictionary的效率高些 ,我就试着将hashtable转成dictionary试试,但为什么

Dictionary<string, string> myDictionary = ht;  (ht是个hashtable)


无法将类型为“System.Collections.Hashtable”的对象强制转换为类型“System.Collections.Generic.Dictionary`2[System.String,System.String]

------解决方案--------------------
一条条转如dic
------解决方案--------------------
这个问题有点。。。。 遍历一遍往DIC里面加 随便说一句 最好借此搞清楚hash和dic的特点 什么场合用。
------解决方案--------------------
hiashtable不是强类型的字典。
二dictionary是强类型的。
没办法直接转换,需要遍历每一条数据,转换成object。