我需要使用Hastable(NotList和 not 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();
}
}
Run Code Online (Sandbox Code Playgroud)
但我有一个错误。当我尝试string item或循环时for,我也遇到错误。