検討:
int x = 10;
とString str = "x";
。
str
value を持つ変数を呼び出して 10 を出力したいx
。しかし、問題は、呼び出されるのがstring x
with""
であることです:
response.write();
どうすればこれを修正できますか?
検討:
int x = 10;
とString str = "x";
。
str
value を持つ変数を呼び出して 10 を出力したいx
。しかし、問題は、呼び出されるのがstring x
with""
であることです:
response.write();
どうすればこれを修正できますか?
あなたはそれをコンテナに包むことができます..次のようなもの:
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 -->);
}
response.write() で x ie 10 の値を出力する必要があると思います。str
次のように、 String variable なしでそれを行うこともできます。
response.write(x);
or response.write(x.ToString());
そして、あなたのコードに従って
int x = 10;
and
String str = x.ToString();
String str = "x" の代わりに。