110,571
社区成员
发帖
与我相关
我的任务
分享
public class Student
{
private string name;
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
}
string a = "Name";
Student s = new Student();
Type t = s.GetType();
PropertyInfo[] p = t.GetProperties();
foreach (PropertyInfo pi in p)
{
if (pi.Name == a)
{
pi.SetValue(s, "Neal", null);
}
}
Console.WriteLine(s.Name);
a = name.ToString();