using System;
using System.Collections.Generic;
using System.Text;
namespace delet
{
class Program
{
static void Main(string[] args)
{
class2 c2 = new class2();
c2.f2();
}
}
public delegate void mydelegate();
class class1
{
public event mydelegate event1;
public void f1()
{
Console.WriteLine("请输入数字");
string s = Console.ReadLine();
if (s == "1")
{
if (event1 != null)
{
event1();//事件发生
}
}
else
{
}
}
}
class class2
{
public void f2()
{
class1 c1 = new class1();
c1.event1 += new mydelegate(function);
c1.f1();
}
private void function()
{
Console.WriteLine("事件发生,输入1");
}
}
}
//有2个类,Clsss1中发生了1个事件,通过委托自动执行Class12中的私有函数function()..