0
在我的代碼中,我在for循環中獲取對象的類型(Party對象),並獲取特定屬性「firstname」的屬性信息。 Party []集合中的所有對象都返回相同的類型,所以我希望在while循環中只獲取一次以外的類型,並且仍然需要能夠從正確的聚會對象中獲取屬性「firstname」。 可以這樣做嗎?謝謝你的幫助。如何在運行時獲取對象集合中的對象類型?
public List<Party> Parties { get; set; }
PropertyInfo info = null;
i = 1
do
{
foreach (Field field in TotalFields)
{
info = Parties[i - 1].GetType().GetProperty("firstname");
//some other code here
}
i++;
} while (i <= Parties.Count);
非常感謝。我想我現在明白了。 – Jyina 2011-04-12 18:09:16