一个简单的问题请赐教这个getValue()方法怎么利用反射取出Name的值public string getValue(Student studen
一个简单的问题 请赐教
这个getValue()方法 怎么利用反射取出Name的值
public string getValue(Student student, string property)
{
//我想取出student.property 的值
}
public void Test()
{
Student student = new Student();
student.Name = "张三";
string value = getValue(student, "Name");
Console.WriteLine(value);
}
这个getValue()方法 怎么利用反射取出Name的值
[解决办法]
上面有点错误
- C# code
return (string)student.GetType().GetProperty(property).GetValue(student, null);
