惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
B
Blog
博客园 - Franky
I
InfoQ
A
About on SuperTechFans
博客园_首页
L
LangChain Blog
量子位
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
美团技术团队
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
G
Google Developers Blog
Last Week in AI
Last Week in AI

博客园 - jeky

rails 路由配置时 URL 地址如何匹配下划线? github.com 不能访问怎么办? Linux - 显示日历的命令 cal 用法 Linux - echo 命令如何追加文本? 如何解决ssh连接后长时间不操作断线的问题? Rails 中如何使用全局变量? raw 允许输出html字符 Linux 用户及组 话说调试 全等(===) 判断一个整数是奇数还是偶数 - jeky - 博客园 选择排序法 让我笔试吃亏"单例模式" 用Javascript实现关键词的高亮显示 Javascript中正则表达式的相识知识 对 TextBox 设置css属性 注意void()里面不能空 - jeky - 博客园 OWC11 实例 访问数组元素的 3 种方法 Internet Explorer 7.0(IE7.0)简体中文版
委托的协变与逆变
jeky · 2009-04-04 · via 博客园 - jeky

★ 协变:

 委托的类型返回值是它所指向函数的返回值得基类.

    private void InitPage()
    {
        HandlerMethod handler1 
= Method1;
        HandlerMethod handler2 
= Method2; // 协变
    }private class Animal { }
    
private class Dog : Animal { }private delegate Animal HandlerMethod();private static Animal Method1() { return null; }
    
private static Dog Method2() { return null; }   

★ 逆变:

委托的类型参数是它所指向函数的参数的派生类.

    private void InitPage()
    {
        HandlerMethod handler1 
= Method1;
        HandlerMethod handler2 
= Method2; // 逆变
    }private class Animal { }
    
private class Dog : Animal { }private delegate void HandlerMethod(Dog dog);private static void Method1(Dog dog) { }
    
private static void Method2(Animal animal) { }