C# 简单事件二
public class BigMan
{
public delegate void OnEventHandler(string arg);
public event OnEventHandler SimpleEvent;
public void DoSomething()
{
Console.WriteLine("事件开始");
if (simpleEvent!= null)
simpleEvent("执行事件...");
Console.WriteLine("事件结束");
}
}
class Program
{
static void Main(string[] args)
{
var m=new BigMan();
m.simpleEvent += (s) =>
{
Console.WriteLine($"{s}");
};
m.DoSomething();
Console.Read();
}
}

浙公网安备 33010602011771号