主人 猫 老鼠
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();
}
}
{
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();
}
}
相关文章推荐
- 猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒
- 猫叫,老鼠逃跑,主人惊醒
- 程序设计: 猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒
- 猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒。(C#语言)(观察者模式)
- .NET面试——老鼠、猫和主人(观察者模式)
- 猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒
- 事件模拟场景:猫叫->老鼠逃跑 & 主人惊醒
- 转---猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒 [观察者模式]
- 连动反应——猫叫 老鼠跑 主人醒
- 一道猫和老鼠吵醒主人的笔试题(C#)
- 一道事件委托面试题 - 猫叫老鼠跑主人醒
- 程序设计(猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒) [转载]
- 程序设计: 猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒。(C#语言)
- 程序设计: 猫叫一声,所有的老鼠都开始逃跑,主人被惊醒 问题解决
- 猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒
- c#的事件机制示例代码: 猫-> 老鼠, 主人
- 由"猫,老鼠和主人"引出的委托,事件及观察者模型问题
- 程序设计_猫老鼠主人
- 猫叫,老鼠逃跑,主人惊醒
- 猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒。(C#语言)