日期:2014-05-17  浏览次数:20383 次

一个简单的问题 请赐教

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