Struct A : ICloneable { public Int32 x; public override String ToString() { return String.Format(”{0}”,x); } public object Clone() { return MemberwiseClone(); } } static void main() { A a; a.x = 100; Console.WriteLine(a.ToString()); Console.WriteLine(a.GetType()); A a2 = (A)a.Clone(); ICloneable c = a2; Ojbect o = c.Clone(); }
因?yàn)锳是值類型,編譯器不會(huì)出現(xiàn)多態(tài)行為。
看到這句話有個(gè)提問。關(guān)于編譯器而言值類型編譯器為什么不會(huì)出現(xiàn)多態(tài)行為?重寫無用?
- 1 回答
- 0 關(guān)注
- 323 瀏覽
添加回答
舉報(bào)
0/150
提交
取消