Re: [問題] 請問繼承同一個父親但是細節不同的類別 …

看板C_Sharp作者 (小朱)時間17年前 (2008/12/14 00:06), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
如果都是繼承自同一個父類別,則可以試試: 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

12/15 12:07, , 1F
謝謝:)
12/15 12:07, 1F
文章代碼(AID): #19GzsNGr (C_Sharp)