看板 C_Sharp 關於我們 聯絡資訊
如果都是繼承自同一個父類別,則可以試試: public class Building { public string Name; } public class School : Building { ... } public class Office : Building { ... } 用這個方法來存: public Building[] myClass; // if class is school: if (myClass[0] is School) { // do something for school class. } else if (myClass[0] is Office) { // do something for office class. } 但如果你想要做到完全與類別無關,那除了使用 Reflection 以外沒有其他方法了... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.84.117.12
funnytseric:謝謝:) 12/15 12:07