using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
    public delegate int Func(int a ,int b);
    public class Test
    {
        public Func<int> Add;        //定义事件
        public event Func funcevent;
        public int a;
        public int b;        public Test(int a, int b)
        {
            this.a = a;
            this.b = b;
        }               public int TestAdd(int i, int b)
        {
           
            return i + b;
            
        }        public int TestMinus(int a, int b)
        {
           
            return a - b;
        }
        #region 事件
            //引发事件的方法
            public void multipli()
            {
                if (funcevent != null)
                {
                    this.funcevent(this.a, this.b);
                }
            } 
        #endregion    }
    class Program
    {
        static void Main(string[] args)
        {
            Test t = new Test(2, 3);            Func fun = t.TestAdd;            fun += t.TestMinus;            Delegate [] DelegateList;            #region 事件
                Program program = new Program();
                    //订阅事件
                t.funcevent += program.t_funcevent;
                    //引发事件
                    t.multipli(); 
            #endregion            DelegateList = fun.GetInvocationList();
            Console.WriteLine("{0}  {1}", DelegateList[0].DynamicInvoke(1, 2), DelegateList[1].DynamicInvoke(3, 5));
            Console.ReadKey();   
        }        #region 事件
            //引发事件的方法
            public int t_funcevent(int a, int b)
            {
                Console.WriteLine("a*b={0}", a * b);
                return a * b;
            } 
        #endregion            
    
    }
}