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(); }
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(); }
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(); }