c# 自定义事件,实现变量的值改变后就触发该事件

public   delegate   void   delegateHandler();   
  public   class   my   
  {   
        public   int   i=0;   
        public   delegateHandler   myhandle;   
        public   int   changeI   
        {   
                  get{return   i;}   
                  set{   
                          i=value;   
                          myhandle();   
                          }   
          }   
  }   
    
  public   class   otherclass   
  {   
        public   my   o;   
        public   otherclass()   
  {       o=new   my();   
  }   
  pulic   void   init()   
  {   
        o.myhandle+=new   delegateHandler(howtodeal);   
  }   
  public   void   howtodeal()   
  {   
        //你自己的处理程序   
  }   
          
    
  }

 

posted on 2013-01-24 15:07  NLazyo  阅读(5113)  评论(0编辑  收藏  举报