这很奇怪,但实际上不知道,为什么下面两个字符串值在代码中不匹配:
string s="TextBox1.Text= \"Hello 1"\";
public static Dictionary<string, string> dictionary =
new Dictionary<string, string>();
dictionary.Add("Button", "TextBox1.Text= \"Hello 1"\");
dictionary.Add("TextBox","TextBox1.Text= \"Hello 1"\");
foreach(KeyValuePair<string,string> pair in dictionary)
{
if(s==pair.Value.ToString())
{
// some code
}
}
真的不知道......可能是什么原因。
答案 0 :(得分:2)
以下是我的更正,对我有用,请参阅带数字的注释
string s="TextBox1.Text= \"Hello 1\""; //1
Dictionary<string, string> dictionary = //2
new Dictionary<string, string>();
dictionary.Add("Button", "TextBox1.Text= \"Hello 1\"");//3
dictionary.Add("TextBox","TextBox1.Text= \"Hello 1\"");//4
foreach(KeyValuePair<string,string> pair in dictionary)
{
if(s==pair.Value.ToString())
{
// some code
}
}