我有一个一流的呼叫人:我可以使用字符串str =“id”,然后person.str = 1吗?
public class Person
{
public int id{get;set;}
public string name{get;set;}
//and many others
}
有没有一种方法来设置值属性不会像正规途径:person.id=1
但使用这样的string str="id"
和person.str=1
?
我想要这样,因为我有很多属性,我收到属性名称和他的价值列表。所以我想,以避免长时间switch-case
及用途:
foreach(var item in MyList.Keys)
{
person.item=MyList[item];
}
你有属性词典吗? – dotnetstep 2011-12-25 12:32:21