码迷,mamicode.com
首页 > 其他好文 > 详细

委托和事件的整理

时间:2014-05-22 02:50:15      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   c   code   java   

bubuko.com,布布扣
  public class UploadEnventcs
    {
        public event EventHandler CreateEvent;
        public delegate void CreateDele(object sender);
        public CreateDele cd;

        public void Upload()
        {
            if (CreateEvent != null)
            {
                Console.WriteLine("CreateEvent绑定的有事件");
                CreateEvent(this, null);
            }
            if (cd != null)
            {
                Console.WriteLine("CreateDele绑定的有事件");
                cd(this);
            }
        }
    }
bubuko.com,布布扣

调用

bubuko.com,布布扣
   class Program
    {
        static void Main(string[] args)
        {
            UploadEnventcs ue = new UploadEnventcs();
            ue.CreateEvent += ue_CreateEvent;
            ue.cd = new UploadEnventcs.CreateDele(CreateDelegate);

            ue.Upload();
        }

        static void ue_CreateEvent(object sender, EventArgs e)
        {
            Console.WriteLine("已执行ue_CreateEvent");
        }
        public static void CreateDelegate(object sender)
        {
            Console.WriteLine("已执行CreateDele委托");
        }
    }
bubuko.com,布布扣

 

委托和事件的整理,布布扣,bubuko.com

委托和事件的整理

标签:style   blog   class   c   code   java   

原文地址:http://www.cnblogs.com/shikyoh/p/3738618.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!