foreach 哈希表中的项目

Kon*_*hov 2 c# hashtable

我需要使用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,我也遇到错误。

Gen*_*mer 5

Hashtable作为DictionaryEntry集合元素

foreach (DictionaryEntry entry in toboofer)
{
    // do something
}
Run Code Online (Sandbox Code Playgroud)

从哈希表中列出myclass

var listOfMyClass = toboofer.Cast<DictionaryEntry>().
                             Select(e => new myclass() 
               { Fio = e.Key.ToString(), About = e.Value.ToString() });
Run Code Online (Sandbox Code Playgroud)