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

I want to use "one" i.e string value of (combobox1.text) as an existing variable string one. Is this possible?

All you still didn't getting my question. I want to use value of combobox1.text that is one and one that is variable string and it value is find. so i want to use variable one's value indirectly.

2
  • one = combobox1.Text? Your question isn't clear. Commented Jun 25, 2012 at 15:13
  • 1
    Very similar to stackoverflow.com/questions/1293549/string-to-variable-name and several others like it. Bundle your string variables into a class and either use Reflection technique or GetProperty. (Not putting this as an answer since I think this question should be closed) Commented Jun 25, 2012 at 15:27

2 Answers 2

5

You cannot do it for local variables like this. For member fields you can use reflection; for locals, the simplest approach is to use Dictionary, for example, like this:

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

combobox1.text = vars["one"];
Sign up to request clarification or add additional context in comments.

Comments

0

you must use:

combobox1.text = one;

Hope it helps

2 Comments

no you didn't understand my question. I want to use combobox1.text's value that is one and one's value that is find.
you want to add to your combobox the word "find" located in the variable one, right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.