我有一個一流的呼叫人:我可以使用字符串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