public string str = "spp";
public string spp = "very good";
public string spp = "very good";
public string myWeb = "abc";
public string myWeb2 = "abc";
public Form3()
{
InitializeComponent();
string str1 = GetName(2); //str1="myWeb"
string str2 = GetName(3); //str2="myWeb2"
string str3 = this.GetType().GetField(str).GetValue(this).ToString(); //str3="very good"
}
public string GetName(int i)
{
System.Reflection.FieldInfo[] fields = this.GetType().GetFields();
return fields[i].Name;
}
传说中的反射,不太明其意及用处,标记一下先~