在MSDN论坛看到有人问:C#里面中将字符串转为变量名
例如:
string str = "spp";

string spp = "very good";

怎样搞 str 而得到 very good 这个值?
 
答案:
InBlock.gifpublic partial class Form1 : Form
InBlock.gif        {
InBlock.gif                string str = "spp";
InBlock.gif                public string spp = "very good";
InBlock.gif
InBlock.gif                public Form1()
InBlock.gif                {
InBlock.gif                        InitializeComponent();
InBlock.gif
InBlock.gif                        MessageBox.Show(this.GetType().GetField(str).GetValue(this).ToString());
InBlock.gif                }
InBlock.gif        }
 
其实平时这样用到很少,但是这个问题至少可以巩固下基础知识和一点小技巧