static void Main(string[] args)
        {
            MyEventPublisher EventPublisher = new MyEventPublisher();


            MyDelegateEventHandler MyAnonymousDelegate = delegate(int x)
            {
                Console.WriteLine("Anonymous Event FIRED!");
            };

            EventPublisher.MyEvent += MyAnonymousDelegate;

            EventPublisher.DoSomething();
        }
Beispiel #2
0
        private void mjButton5_Click(object sender, EventArgs e)
        {
            string Is_Delegate_name;
            MyDelegateEventHandler myDelegate;

            myDelegate  = new MyDelegateEventHandler(MyMethod3);
            myDelegate += new MyDelegateEventHandler(MyMethod1);//合并第二个方法
            //--------委托索引
            if (myDelegate != null)
            {
                System.Delegate[] dels = myDelegate.GetInvocationList();
                for (int i = 0; i < dels.Length; i++)
                {
                    Is_Delegate_name = Convert.ToString(dels[i].Method);
                }
            }
            var send = myDelegate("123");//调用委托

            MessageBox.Show(Convert.ToString(send));
        }
Beispiel #3
0
 void Start()
 {
     myDelegate += Test;
 }