コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Delegate Covariance *****\n");
            ObtainVehicalDelegate targetA = new ObtainVehicalDelegate(GetBasicCar);
            Car c = targetA();

            Console.WriteLine("Obtained a {0}", c);

            // Covariance allows this target assignment.
            ObtainVehicalDelegate targetB = new ObtainVehicalDelegate(GetSportsCar);
            SportsCar             sc      = (SportsCar)targetB();

            Console.WriteLine("Obtained a {0}", sc);
            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: simple555a/DotNetAppDev
        static void Main(string[] args)
        {
            Console.WriteLine("***** Delegate Covariance *****\n");
            ObtainVehicalDelegate targetA = new ObtainVehicalDelegate(GetBasicCar);
            Car c = targetA();

            Console.WriteLine("Obtained a {0}", c);

            // Делегаты ковариантны.
            ObtainVehicalDelegate targetB = new ObtainVehicalDelegate(GetSportsCar);
            SportsCar             sc      = (SportsCar)targetB();

            Console.WriteLine("Obtained a {0}", sc);
            Console.ReadLine();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: linuxemb/C_sharp
        static void Main(string[] args)
        {
            Console.WriteLine("***** Delegate Covariance *****\n");
            ObtainVehicalDelegate targetA = new ObtainVehicalDelegate(GetBasicCar);
            Car c = targetA();

            Console.WriteLine("Obtained a {0}", c);

            // Covariance allows this target assignment.
            ObtainVehicalDelegate targetB = new ObtainVehicalDelegate(GetSportsCar);
            // performe an explicit cast to bbtain access to the members of the devied type
            SportsCar sc = (SportsCar)targetB();

            Console.WriteLine("Obtained a {0}", sc);
            Console.ReadLine();
        }