WHH

          事件是一种特殊的委托,事件只属于对象,是对委托访问的限制。

          举个例子:

          public delegate int  DoSth(int a,int b);

          public class A

          {

                   public int doadd(int aa,int bb)

                   {

                        return aa+bb;

                    }

           }

           public class B

           {

                  public DoSth dosth;

            }

          

          .....

          A objA = new A();

          A objA2 = new A();

          B objB= new B();

          objB.dosth += new DoSth (objA.doadd);

          objB.dosth += new DoSth (objA2.doadd);

          objB.dosth(1,5);

这样看来,objB可以订阅很多事件,符合订阅的参与方都可以。

 

相关文章:

  • 2021-10-06
  • 2021-12-26
  • 2021-07-04
  • 2021-07-08
  • 2022-12-23
  • 2021-09-04
  • 2021-04-04
猜你喜欢
  • 2022-12-23
  • 2021-08-21
  • 2021-06-27
  • 2021-08-15
  • 2022-12-23
  • 2021-05-18
相关资源
相似解决方案