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

原帖链接在此。

作者:泥塘·物语
出处:泥塘·物语
本站博客文章已停止更新,请移步 泥塘·物语

原文地址:https://www.cnblogs.com/danshui/p/2856828.html