C#将字符串转为变量名

mac2022-06-30  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()); } }原文出处:http://social.microsoft.com/Forums/zh-CN/visualcshartzhchs/thread/3b7c7d4d-925b-4d72-bee0-6c39c2e2786b

转载于:https://www.cnblogs.com/ttssrs/archive/2012/03/14/2396508.html

最新回复(0)