如何使用变量来识别C#中的另一个变量?

Mat*_*Sot 0 c#

有没有办法基本上这样做:

string x = "hi";
int hi = 3;
Console.WriteLine([x].ToString());
Run Code Online (Sandbox Code Playgroud)

得到我想要做的事情?我想打印"3",而不是"喜欢".我想用x来引用hi.我怎么能这样做?

rcr*_*ens 5

字典怎么样?

Dictionary<string, int> data = new Dictionary<string, int>();
data["hi"] = 3;

Console.WriteLine(data["hi"]); // prints 3
Run Code Online (Sandbox Code Playgroud)

  • 你的例子中是否应该反转int和string来完成他想要的东西?还是我只是在密集? (4认同)