예제 #1
0
        public int Add(int a, int b)
        {
            EventHandler <IntEventArgs> before = this.BeforeAdd;

            if (before != null)
            {
                IntEventArgs e1 = new IntEventArgs {
                    Number = a
                };
                before(this, e1);
                a = e1.Number;                          // 重新从事件参数中取值,因为有可能会在事件中修改
            }

            int c = a + b;

            EventHandler <IntEventArgs> after = this.AfterAdd;

            if (after != null)
            {
                IntEventArgs e2 = new IntEventArgs {
                    Number = c
                };
                after(this, e2);
                c = e2.Number;                          // 重新从事件参数中取值,因为有可能会在事件中修改
            }

            return(c);
        }
예제 #2
0
        public int Add(int a, int b)
        {
            EventHandler <IntEventArgs> before = this.BeforeAdd;

            if (before != null)
            {
                IntEventArgs e1 = new IntEventArgs {
                    Number = a
                };
                before(this, e1);
                a = e1.Number;                      // 重新从事件参数中取值,因为有可能会在事件中修改
            }

            return(a + b);
        }
예제 #3
0
 void instance_BeforeAdd(object sender, IntEventArgs e)
 {
     e.Number += 5;
 }
예제 #4
0
 void instance_AfterAdd(object sender, IntEventArgs e)
 {
     e.Number += 20;
 }