讲的特别好,请问有代码吗?
using System;
namespace demo8
{
class Program
{
static void Main(string[] args)
{
Client c1 = new Client();
Client c2 = new Client();
Dog.NewDog += c1.WantADog;
Dog.NewDog += c2.WantADog;
Dog dog = new Dog("tom");
}
}
public class Dog
{
static int Num;
public delegate void Hander();
public static event Hander NewDog;
public Dog(string name)
{
Num++;
if (NewDog != null)
{
NewDog();
}
}
}
class Client
{
public void WantADog()
{
Console.WriteLine("我想要一条狗");
}
}
}
自己下软件跟着敲赛。