例如
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());
}
}
本文介绍了一种使用C#反射来获取对象属性值的方法。通过实例化一个包含特定属性的类,并利用反射机制,可以动态地访问这些属性并获取其值。
168

被折叠的 条评论
为什么被折叠?



