当前位置: 代码迷 >> ASP.NET >> 一个简单的有关问题 请赐教
  详细解决方案

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

热度:6142   发布时间:2013-02-25 00:00:00.0
一个简单的问题 请赐教

这个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);
  相关解决方案