您的位置:首页 > 其它

主人 猫 老鼠

2009-06-10 23:20 211 查看
class cat
{
public event EventHandler miao;

protected virtual void onmiao(EventArgs e)
{
if (miao != null)
miao(this, e);

}

public void domiao()
{
Console.WriteLine("cat miao");
onmiao(EventArgs.Empty);

}

}

class mouse
{
public void run(object sender, EventArgs e)
{
Console.WriteLine("mouse run..");

}

}
class owner
{
public void noise(object sender, EventArgs e)
{
if (sender is cat)
Console.WriteLine("heard cat miao..");
else
Console.WriteLine("heard mouse noise");
Console.WriteLine("owner wake...");
}

}

class Program
{
static void Main(string[] args)
{

cat cat = new cat();
mouse m = new mouse();
owner o = new owner();
cat.miao += m.run;
cat.miao += o.noise;
cat.domiao();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: