is there way if have string containing name of defined variable, can call variable. example:
string hello = "hello"; console.writeline("what name if variable?"); userinput = console.readline(); userinput.replace('hello', 'hi'); <---//this replace value of hello not value of userinput
how let user input variable name use string call variable?
the practical merit of question unclear. purpose have described, may use dictionary
object (key-value <string, string>
) , operate on it: example, if user provides key
, can modify value
or compose string containing value
, pertinent business logic.
following sample use of dictionary
object pertinent similar use-case in console app:
dictionary<string, string> names = new dictionary<string, string> { {"1", "john"}, {"2", "anna"}, {"3", "gary"}, {"4", "jacob"}, {"5", "jennifer"} }; console.writeline("what id?"); string userinput = console.readline(); if (names.keys.contains(userinput)) { console.writeline("hello " + names[userinput] + "! nice see online."); } else { console.writeline("sorry, not valid id. bye."); } console.writeline("press key exit."); console.readkey();
hope may help.
Comments
Post a Comment