日期:2014-05-17  浏览次数:20765 次

C#中event基本使用

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            SendCls sc = new SendCls();
            sc.eveMyeve += new SendCls.deleMydele(sc_eveMyeve);
            sc.run();
        }

        static void sc_eveMyeve()
        {
            Console.WriteLine("事件已响应");
            Console.ReadKey();
        }
    }

    class SendCls
    {
        public delegate void deleMydele(); //声明一个无参数返回值为空的代理
        public event deleMydele eveMyeve;  //声明该代理类型的事件, 

        public void run()
        {
            for (int i = 0; i < 99999;i++ )
            {
                if (i==99990)
                {
                    eveMyeve();
                }
            }
        }
    }
}
?