static void Main(string[] args) { //正常的匹配 返回父类 输入形参:无 HandlerMethod handler1 = FirstHandler; handler1(); //协变 返回值Dog默认转换为Mammal(父类中装子类) HandlerMethod handler2 = SecondHandler; handler2(); //创建父类的对象 Manmal m = new Manmal(); //正常匹配 无返回值,输入的形参为父类 HandleModthod1 handler11 = ThirdHandler; handler11(m); //创建子类的对象 Dog d = new Dog(); //逆变,参数Dog默认可以转换成为Mammal HandleModthod2 handle33 = ThirdHandler; handle33(d); }
public static void ThirdHandler(Manmal m) { Console.WriteLine("Third Handler"); }