名称dosent存在于当前上下文错误

时间:2016-12-12 06:20:51

标签: c# winforms

 public Dictionary<string, TextBox> name_tbs = new Dictionary<string, TextBox>();
    TextBox TextBoxbyName(string tb_name)
    {
        return name_tbs(tb_name);
    }

现在它显示了当前上下文中存在的错误name_tbs dosent。

1 个答案:

答案 0 :(得分:1)

您需要将其放在[]中,因为您正在使用字典的键进行访问,

Dictionary<string, TextBox> name_tbs = new Dictionary<string, TextBox>();     
TextBox TextBoxbyName(string tb_name)
{           
  return name_tbs[tb_name];
}