将字符串转为变量名(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());
        }
    }


你可能感兴趣的:(ASP.NET)