看板 C_Sharp 關於我們 聯絡資訊
假如我有一個class M class M { ... } 還有一個繼承M的class MC class MC : M { private int x; public int X { set {x=value;} get {return x;} } } 如果我要在main裡面這樣做的話 public static void Main(String[] args) { M test = new MC(); test.X = 100; } 這時會出現一個問題,test沒辦法使用MC的成員... 請問我的問題出在哪裡呢? 感謝指教~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.16.14
saitoh:new出來的都是M了不認得MC的東西很正常 11/01 18:29
gamecubemomo:那樣怎麼改才能讓她是Mtype又有MC的成員 11/01 18:55
EricTsai:((MC)test).X or (test as MC).X 11/01 19:41