I have a program in which a user types in the name of the variable they want to change. So we have this:
string user_input = "age";
And I have a class with the following:
class Jim{
public static int age = 10;
public static bool married = false;
public static string name = "John";
}
I now want to print the value of the variable that the user entered. So since the user typed in age
I want to print Jim.age
. How can I convert user_input
into something that lets me access the class. I really want to do Jim[input_string]
like you can in JS, but I believe this is possible.
I would use a dictionary to store all of the variables associated with Jim
but you can't make a Dictionary
which maps as <string, bool or int or string>
.