小编Kon*_*hov的帖子

foreach 哈希表中的项目

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

c# hashtable

2
推荐指数
1
解决办法
4269
查看次数

标签 统计

c# ×1

hashtable ×1