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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
N
News and Events Feed by Topic
S
Secure Thoughts
Vercel News
Vercel News
S
Security @ Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题
Hacker News: Ask HN
Hacker News: Ask HN
博客园 - 聂微东
WordPress大学
WordPress大学
Google Online Security Blog
Google Online Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
PCI Perspectives
PCI Perspectives
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
Apple Machine Learning Research
Apple Machine Learning Research
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threat Research - Cisco Blogs
博客园 - 司徒正美
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
A
About on SuperTechFans
P
Proofpoint News Feed
大猫的无限游戏
大猫的无限游戏
V
V2EX
I
Intezer
H
Hacker News: Front Page
www.infosecurity-magazine.com
www.infosecurity-magazine.com
L
Lohrmann on Cybersecurity
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
博客园 - 叶小钗
The Cloudflare Blog
月光博客
月光博客
W
WeLiveSecurity
T
Tenable Blog
P
Proofpoint News Feed
aimingoo的专栏
aimingoo的专栏
Help Net Security
Help Net Security
L
LangChain Blog
C
CERT Recently Published Vulnerability Notes
T
The Exploit Database - CXSecurity.com
美团技术团队
B
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();
        }
    }

}