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

推荐订阅源

月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
B
Blog
博客园 - Franky
小众软件
小众软件
Recorded Future
Recorded Future
B
Blog RSS Feed
爱范儿
爱范儿
宝玉的分享
宝玉的分享
L
LangChain Blog
博客园 - 【当耐特】
The Register - Security
The Register - Security
P
Proofpoint News Feed
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
雷峰网
雷峰网
Last Week in AI
Last Week in AI
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
M
MIT News - Artificial intelligence
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
aimingoo的专栏
aimingoo的专栏
D
Docker
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
有赞技术团队
有赞技术团队
G
Google Developers Blog
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog

博客园 - 旴江老段

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

}