0
点赞
收藏
分享

微信扫一扫

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

心如止水_c736 2022-02-22 阅读 74


例如


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

        }

    }


举报

相关推荐

0 条评论