Пример #1
0
    public static int Main()
    {
        // Declared type of 'd' has final method Foo(), so calls to
        // Foo() will devirtualize.
        //
        // However the jit does not know that d's type is exact so
        // currently the calls to Bar() will not devirtualize.
        Derived d = new Derived();

        d.Foo();
        d.Bar();

        // M should inline and expose an exact return type
        // which will trigger late devirt for both Foo() and Bar().
        M().Foo();
        M().Bar();

        // Copy via 'b' currently inhibits devirt
        Base b = M();

        b.Foo();
        b.Bar();

        // Direct use of newobj gives exact type so all these
        // will devirtualize
        new Base().Foo();
        new Base().Bar();
        new Derived().Foo();
        new Derived().Bar();

        return(100);
    }
Пример #2
0
    static void Main()
    {
        Base x = new Derived();

        x.Foo += (sender, e) => { };
        x.Bar();
        Base x2 = new Derived2();

        x2.Foo += (sender, e) => { };
        x2.Bar();
    }