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

推荐订阅源

The GitHub Blog
The GitHub Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Y
Y Combinator Blog
B
Blog RSS Feed
K
Kaspersky official blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Know Your Adversary
Know Your Adversary
C
CERT Recently Published Vulnerability Notes
V
Vulnerabilities – Threatpost
C
Check Point Blog
L
LINUX DO - 热门话题
Simon Willison's Weblog
Simon Willison's Weblog
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Hacker News
The Hacker News
P
Palo Alto Networks Blog
L
Lohrmann on Cybersecurity
T
Tor Project blog
T
Tenable Blog
H
Help Net Security
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学
Cisco Talos Blog
Cisco Talos Blog
T
Threatpost
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Schneier on Security
G
Google Developers Blog
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
Microsoft Azure Blog
Microsoft Azure Blog
Cyberwarzone
Cyberwarzone
Security Latest
Security Latest
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
美团技术团队
博客园 - 三生石上(FineUI控件)
Latest news
Latest news
腾讯CDC
G
GRAHAM CLULEY
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
博客园 - 【当耐特】
C
CXSECURITY Database RSS Feed - CXSecurity.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
Martin Fowler
Martin Fowler

博客园 - 旴江老段

如何开发和维能hold住全场的软件 什么样的软件才能hold住全场 SNOOP 开发WPF的好工具 被遗忘的事物 前台线程和后台线程(Foreground and Background Threads) runtime binding policy Checking space used in a database AsyncCallback方法和主线程怎么同步呢? Remoting Practice Sample Using Custom Assemblies with Reports 为什么32位的CPU?为什么32位的CPU只能支持4G的内存呢? 学习SSL和certificate的好网页 Wix Upgrade怎么判断是否更新 学WIX的好网站 SELECT @local_variable (Transact-SQL) sql server try catch and transaction的几个要点 使SQL关键字变大写的小工具 Assert.AreEqual .net 异步调用机制
委托和事件的区别
旴江老段 · 2012-04-20 · via 博客园 - 旴江老段

我想我知道委托和时间的区别了

委托可以被外部调用 

 namespace GrammerTest

{
    public delegate void FuncDelegate();
    public class DelegateTest
    {
        public FuncDelegate FuncDelegateObject;
        public  DelegateTest()
        {
            FuncDelegateObject = Func1;
            FuncDelegateObject += Func2;
        }

        public void Func1()
        {
            Console.WriteLine("Func 1");
        }

        public void Func2()
        {
            Console.WriteLine("Func 2");
        }
    }
}

         private static void Main()

        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //new ForeachNullList().Run();

            new DelegateTest().FuncDelegateObject();

            Console.Read();
            //Application.Run(new Form1());
        }

事件不可以从类的外部发动

 using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GrammerTest
{
    public delegate void ADelegate();
    public class EventPublisher
    {
        public event ADelegate AEvent;
        public void Fire()
        {
            if (AEvent != null)
                AEvent();
        } 
  
    }

    internal class EventClient
    {

        public void Func1()
        {
            Console.WriteLine("Func 1");
        }
    }

    internal class EventClient2
    {
        public void Func2()
        {
            Console.WriteLine("Func 2");
        }
    }

    class EventTest
    {
        public void Run()
        {
            EventPublisher ep = new EventPublisher();
            EventClient ec1 = new EventClient();
            EventClient2 ec2 = new EventClient2();
            ep.AEvent += ec1.Func1;
            ep.AEvent += ec2.Func2;

            //ep.AEvent(); doesn't work
            
//only
            ep.Fire();
        }
    }

}