现在的位置: 首页 > 综合 > 正文

C#里面中将字符串转为变量名

2013年02月15日 ⁄ 综合 ⁄ 共 308字 ⁄ 字号 评论关闭

例如

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());
        }
    }

抱歉!评论已关闭.