读书人

一个简单的有关问题 请赐教

发布时间: 2012-06-23 14:52:43 作者: rapoo

一个简单的问题 请赐教

这个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); 

读书人网 >asp.net

热点推荐