Consider:
int x = 10;
and String str = "x";
.
I want to output 10 by calling the str
variable as it has value x
. But the problem is it is a string x
with ""
to be called in:
response.write();
How can I fix this?
Consider:
int x = 10;
and String str = "x";
.
I want to output 10 by calling the str
variable as it has value x
. But the problem is it is a string x
with ""
to be called in:
response.write();
How can I fix this?
You can wrap it in a container.. something like this:
class Container {
public int X { get; set; }
public Container() {
X = 10;
}
}
// .. elsewhere...
object getVariableValueByStringName(string str) {
return typeof(Container).GetProperty(str).GetValue(new Container() /* <-- dummy or not.. up to you -->);
}
I think you need to output the value of x i.e. 10 in response.write(). You can even do that without the String variable str
, like:
response.write(x);
or response.write(x.ToString());
And as per your code
int x = 10;
and
String str = x.ToString();
instead of String str = "x".