c#字典问题(密钥不存在) [英] c# dictionary issue ( key was not present )

查看:130
本文介绍了c#字典问题(密钥不存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,感谢你们查看我的帖子 

hello all thank you for viewing my post 

好吧我真的很喜欢字典的东西,但是我设法写了这个,但问题是我说它不是出现在字典中但形成第一张图片,你可以看到它清楚地显示在那里,我不知道为什么它不工作 

ok i'm really new to dictionary stuff but i managed to write this but issue i have is it says its not present in dictionary yet form 1st image you can see it clearly shows it there and im not sure why its not working 

当我运行它时它会在这里给我这个错误 

and i had when i run it it gives me this error here 

不确定我做错了什么或为什么它没有在字典中,一旦我有这个我也能够在文本框中键入文本并将值保存回文件它打开表单,我不知道如何做到这一点也很抱歉是一个痛苦这个
是我目前使用的代码 

not sure what i am doing wrong or why its not in dictionary once i have this down i also what to be able to type text into the text box and save the value back to the file it opend form and i have no idea how to do that as well its sorry to be a pain this is the code im currently using 

        public void testweapon()
        {

            Dictionary<string, string> _werFileContent =
            new Dictionary<string, string>();
            using (StreamReader sr = new StreamReader(@"C:\Program Files (x86)\Activision\Call of Duty - World at War\raw\weapons\sp\usr"))
            {

                string _line;
                while ((_line = sr.ReadLine()) != null)
                {
                    string[] keyvalue = _line.Split('\\');
                    if (keyvalue.Length == 2)
                    {
                        _werFileContent.Add(keyvalue[0], keyvalue[1]);
                    }
                }
                maxammo.Text = _werFileContent["maxAmmo"];

            }
        }

提前谢谢你elfenliedtopfan5

thank you in advance elfenliedtopfan5

推荐答案

如果查看第二张图片,在底部的Autos中可以看到字典为空(Count = 0);

If you look at the second pic, in the Autos at the bottom you can see that the dictionary is empty (Count = 0);

您能告诉我们您要阅读的文件吗?

Can you show us the file you are trying to read?


这篇关于c#字典问题(密钥不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆