-10
string one = "find";
combobox1.text = "one";

我想使用“一个”,即 ( combobox1.text) 的字符串值作为现有变量string one。这可能吗?

所有你仍然没有得到我的问题。我想使用combobox1.text的值,它是一个一个是变量字符串,它的值是find。所以我想间接使用变量one的值。

4

2 回答 2

5

对于这样的局部变量,您不能这样做。对于成员字段,您可以使用反射;对于当地人来说,最简单的方法是使用Dictionary,例如,像这样:

IDictionary<string,string> vars = new Dictionary<string,string> {
    {"one", "find"}
,   {"two", "cancel"}
};

combobox1.text = vars["one"];
于 2012-06-25T15:18:49.927 回答
0

你必须使用:

combobox1.text = one;

希望能帮助到你

于 2012-06-25T15:13:24.983 回答