Exemple #1
0
    static void Main()
    {
        SecondDerived derived = new SecondDerived();
        BaseClass     mybc    = (BaseClass)derived;

        derived.Print();
        mybc.Print();
    }
    static void Main()                                // Main
    {
        SecondDerived derived = new SecondDerived();  // Use SecondDerived.
        MyBaseClass   mybc    = (MyBaseClass)derived; // Use MyBaseClass.

        derived.Print();
        mybc.Print();
    }
    static void Main()
    {
        SecondDerived derived = new SecondDerived();
        // we have cast SecondDerived to the type BaseClass.
        //This is perfectly legal code (as we saw in the Polymorphism example).
        BaseClass mybc = (BaseClass)derived; //upcast

        derived.Print();
        mybc.Print();
    }