0
如果一個類聲明瞭一個事件,那麼只能從該類中觸發事件。限制事件調用的原因是什麼?事件調用
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication12
{
delegate void Function();
class EventHandling
{
public event Function fun;
public void AddEvents(Function events)
{
fun += events;
}
public void Notify()
{
fun();
}
}
class Program
{
static void Main(string[] args)
{
EventHandling aEvtHandler = new EventHandling();
Function aFun = new Function(Display);
aEvtHandler.AddEvents(aFun);
aEvtHandler.Notify();
}
static void Display()
{
Console.WriteLine("in the display");
Console.Read();
}
}
}