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 { }

posted @ 2009-11-21 20:03  BloodyAngel  阅读(214)  评论(2编辑  收藏  举报