// public event MenuHandler MenuSelection;
// public void Say()
// {
// Console.WriteLine("这是事件吗?");
// }
// }
public delegate void aa(string name);
public class bb
{
public event aa cc;
public void dd(string name)
{
if (cc!= null)
{
cc(name);//调用委托和使用委托
}
else
{
Console.WriteLine("错误调用");
}
}
public void ee(string name)
{
Console.WriteLine("完毕!");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace demo1
{
class Program
{
public delegate void TestDelegate(string name);
static void Main(string[] args)
{
//Program a=new Program();
//TestDelegate test = a.say;
//test += a.say;
//test("chaiyesong");
//Console.WriteLine("====================");
//a.say("chaiyesong");
//test -= a.say;
//test("aa");
//EventAndDelegate tet = new EventAndDelegate();
//tet.MenuSelection += new MenuHandler(tet.Say);
bb jj = new bb();
jj.cc+= new aa(jj.ee);//绑定委托的事件只有事件绑定了委托才能用事件调用委托
jj.dd("chaiyesong");//调用方法启动事件激活事件//调用事件调用委托