【发布时间】:2013-12-02 20:47:40
【问题描述】:
这个问题不是为什么它给出错误..而是为什么它没有给出一个错误......
private void Form1_Load(object sender, EventArgs e)
{
Dictionary<string, string> dic = new Dictionary<string, string>();
dic["666bytes"] = "ME";
MessageBox.Show(dic["should_give_error"]);
}
这应该会报错,对吧?因为 dic["should_give_error"] 不存在但它没有给出错误(表单正常加载)。但是我可以用 try..catch(KeyNotFoundException) 块来捕获它......怎么会?
【问题讨论】:
-
你确定你的表单加载事件真的被连接了吗?
-
@JonSkeet :是的,我什么都能正常做
标签: c# winforms dictionary