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

推荐订阅源

L
LangChain Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Attack and Defense Labs
Attack and Defense Labs
T
Tor Project blog
Scott Helme
Scott Helme
Schneier on Security
Schneier on Security
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Security @ Cisco Blogs
GbyAI
GbyAI
Help Net Security
Help Net Security
T
Troy Hunt's Blog
Recent Announcements
Recent Announcements
Engineering at Meta
Engineering at Meta
L
LINUX DO - 最新话题
TaoSecurity Blog
TaoSecurity Blog
AWS News Blog
AWS News Blog
Y
Y Combinator Blog
SecWiki News
SecWiki News
Microsoft Azure Blog
Microsoft Azure Blog
Spread Privacy
Spread Privacy
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Google DeepMind News
Google DeepMind News
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
S
Securelist
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
雷峰网
雷峰网
H
Help Net Security
AI
AI
The Hacker News
The Hacker News
B
Blog
罗磊的独立博客
L
Lohrmann on Cybersecurity
爱范儿
爱范儿
C
Cisco Blogs
有赞技术团队
有赞技术团队
Project Zero
Project Zero
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Secure Thoughts
A
Arctic Wolf
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Latest news
Latest news
Cloudbric
Cloudbric
D
Docker
博客园 - 叶小钗
月光博客
月光博客

博客园 - 旴江老段

如何开发和维能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();
        }
    }

}