referring to a field indirectly
Posted: June 9th, 2020, 4:52 pm
Is it possible to change the contents of a variable without knowing its name?
For example I want to change the contents of a variable named SEX.
So I can write
SEX = 2;
Can I write something like:
string varname = "sex";
setContents(varname, 2);
which would do the same as the direct assigning.
Why would I need that?
I have a need to edit some variables according to some user commands. So I thought about having an excel file with three columns:
1. Id
2. variable
3. new_value
Reading this file and for each line in the file apply the change accordingly.
For example I want to change the contents of a variable named SEX.
So I can write
SEX = 2;
Can I write something like:
string varname = "sex";
setContents(varname, 2);
which would do the same as the direct assigning.
Why would I need that?
I have a need to edit some variables according to some user commands. So I thought about having an excel file with three columns:
1. Id
2. variable
3. new_value
Reading this file and for each line in the file apply the change accordingly.