090713 T 数组不OO

时间:2022-04-24
本文章向大家介绍090713 T 数组不OO,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

数组并不满足OO的替换……(同样的东西还有struct等)


    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);  
        Son[] sons = new Son[5];
        Father[] fathers = sons;
        TestMethod(fathers);
    }
    private void TestMethod(Father[] ff)
    {
        ff[0] = new Daughter();//Here throw a exception.
    }  
    private class Father { }
    private class Daughter : Father { }
    private class Son : Father { }