【发布时间】:2015-05-12 11:43:28
【问题描述】:
我需要使用Hastable(不是List 而不是Dictionary),而且我有很多带键的变量。我在类中添加键和变量,并在我的程序中使用它。但我不知道如何解析Hashtable。我试过这个:
Hashtable toboofer = null;
string path = @"my.bin";
FileStream fin = File.OpenRead(path);
try
{
BinaryFormatter bf = new BinaryFormatter();
toboofer = (Hashtable)bf.Deserialize(fin);
for (int i = 0; i <= toboofer.Count; i++ )
//foreach (KeyValuePair<string, string> kvp in toboofer)
{
myclass cl = new myclass();
cl.Fio = toboofer[i].ToString();
cl.About = toboofer[i].ToString();
}
}
但我有一个错误。当我尝试string item 或循环for 时,我也遇到了错误。
【问题讨论】:
-
你得到什么错误?
-
你真的应该考虑使用强类型
Dictionary<TKey, TValue>而不是Hashtable。 -
那么,为什么
Dictionary<,>和List<>解决方案不可接受?可能有一种方法可以回避有助于此解析部分的要求。 -
字典和列表不会从二进制文件中分离出来。可能是我错了