C# 委托事件, 发布者订阅者模式简单的demo
作者:互联网
public class Publisher { public void Print() { Console.WriteLine("来活了"); } }
class Subscriber { public delegate void NumManipulationHandler(); public event NumManipulationHandler DoJobEvent; public void StatusChanged() { if (DoJobEvent != null) { DoJobEvent(); Console.WriteLine("唉,又要干活了。。。"); Console.ReadLine(); } else { Console.WriteLine("还没来活呀。。。"); Console.ReadKey(); } } }
public class Program { static void Main(string[] args) { Publisher publisher = new Publisher(); Subscriber subscriber = new Subscriber(); subscriber.DoJobEvent += publisher.Print; subscriber.StatusChanged(); } }
标签:DoJobEvent,Console,WriteLine,C#,demo,void,Subscriber,发布者,public 来源: https://www.cnblogs.com/peanuter/p/15467715.html