在c#中使用string作为现有变量

Pri*_*123 -10 c# variables

string one = "find";
combobox1.text = "one";
Run Code Online (Sandbox Code Playgroud)

我想使用"one"即字符串值(combobox1.text)作为现有变量string one.这可能吗?

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

das*_*ght 5

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

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

combobox1.text = vars["one"];
Run Code Online (Sandbox Code Playgroud)