主人 猫 老鼠

it2025-12-16  16

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();        }    }

 

转载于:https://www.cnblogs.com/wolfcool/archive/2009/06/10/1500971.html

相关资源:数据结构—成绩单生成器
最新回复(0)