C# 简单事件二

    public class BigMan
    {
        public delegate void OnEventHandler(string arg);

        public event OnEventHandler SimpleEvent;

        public void DoSomething()
        {
            Console.WriteLine("事件开始");
            if (simpleEvent!= null)
                simpleEvent("执行事件...");
            Console.WriteLine("事件结束");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var m=new BigMan();
            m.simpleEvent += (s) =>
            {
                Console.WriteLine($"{s}");
            };

            m.DoSomething();
            Console.Read();
        }
    }
posted @ 2017-11-27 11:12  野生中的码农  阅读(159)  评论(0)    收藏  举报