将字符串转为变量名(C#)
问题提出:
string str = "spp"; string spp = "very good";
如何输出str的值是“very good”?
精彩回答:
public partial class Form1 : Form { string str = "spp"; public string spp = "very good"; public Form1() { InitializeComponent(); MessageBox.Show(this.GetType().GetField(str).GetValue(this).ToString()); } }