using System;
using System.Collections.Generic;
using System.Text;
namespace @event
{
class Program
{
static void Main(string[] args)
{
Person p = new Person();
p.eventCall+=new Person.Call(Call);
p.Notier();
Console.Read();
}
public static void Call()
{
Console.Write("/n这是一个测试程序/n");
}
}
class Person
{
public delegate void Call();
public event Call eventCall;
public void Notier()
{
if (eventCall != null)
{
eventCall();
}
}
}
}
本文介绍了一个简单的 C# 事件机制示例程序。通过定义委托类型 Call 和事件 eventCall,当 Notier 方法被调用时触发事件,进而执行绑定到事件上的 Call 方法。此示例展示了如何创建事件、绑定事件处理程序以及触发事件。

3749

被折叠的 条评论
为什么被折叠?



