我可能在這裏缺少基本知識,但我會去找它並提出問題。如何在C中動態獲取類元素
比方說,我們有一個字符串數組:
,我們有一個類:
public class InventoryItem
{
public string ItemCode { get; set; }
public string ItemDescription { get; set; }
}
我希望能夠引用動態基於價值觀的InventoryItem的屬性的陣列。
我需要遍歷數組並通過數組的當前字符串成員來獲取類的屬性值。
我該怎麼辦?
如何ItemCode和ItemDescription申報? InventoryItem還在哪裏,請顯示代碼。 – 2012-07-06 10:16:17
一種選擇是使用反射。見[這裏] [1]。 [1]:http://stackoverflow.com/questions/1196991/get-property-value-from-string-using-reflection-in-c-sharp – Maarten 2012-07-06 10:17:08