示例#1
0
        public void ContraVarianceSample()
        {
            Child1ReturnClass CR1 = new Child1ReturnClass()
            {
                ChildMessage1 = "ChildMessage1"
            };
            contravrianceDelegate cdel = new HelperClass().Method1;

            cdel(CR1);
        }
示例#2
0
        public void CoVarianceSample()
        {
            covrianceDelegate cdel;

            cdel = new HelperClass().ChildMehod1;
            Child1ReturnClass CR1 = (Child1ReturnClass)cdel();

            Console.WriteLine(CR1.ChildMessage1);
            cdel = new HelperClass().ChildMehod2;
            Child2ReturnClass CR2 = (Child2ReturnClass)cdel();

            Console.WriteLine(CR2.ChildMessage2);
        }