用户操作
[留言]  [发消息]  [加为好友] 
订阅我的博客
XML聚合    FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
zengxie的公告
文章分类
    存档

    原创  猫叫,老鼠逃,人醒 收藏

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace delegateEvent
    {
        class callEventArgs : System.EventArgs
        {
            private string Name;
            public callEventArgs(string CName)
            {
                this.Name = CName;
            }
            public string name
            {
                get
                {
                    return Name;
                }
                set
                {
                    this.Name = value;
                }
            }
        }
        public delegate void CallEventHandler(object sender,callEventArgs e);
     class Cat
     {
            public event CallEventHandler Call;
            public virtual void OnCall(callEventArgs e)
            {
                if (Call != null)
                {
                    Call(this, e);
                }
            }
            public void Calling(string CatName)
            {
                Console.WriteLine("猫大叫");
                OnCall(new callEventArgs(CatName));
            }
     }
        class Mouse
        {
            private string Name;
            public Mouse(string MName)
            {
                this.Name = MName;
            }
            public string mName
            {
                get
                {
                    return Name;
                }
                set
                {
                    this.Name = value;
                }
            }
            public void Response(object sender, callEventArgs e)
            {
                Console.WriteLine(Name+"四处逃跑");
            }
        }
        class Person
        {
            private string Name;
            public Person(string PName)
            {
                this.Name = PName;
            }
            public string pName
            {
                get
                {
                    return Name;
                }
                set
                {
                    this.Name = value;
                }
            }
            public void Response(object sender, callEventArgs e)
            {
                Console.WriteLine(Name + "醒了");
            }
        }
        class Relation
        {
            static void Main()
            {
                Cat cat = new Cat();
                Mouse mouse = new Mouse("kitty");
                Person men = new Person("Person");
                cat.Call+=new CallEventHandler(mouse.Response);
                cat.Call+=new CallEventHandler(men.Response);
                cat.Calling("cat");
           
            }
        }
    }
     

    发表于 @ 2007年06月16日 15:33:00 | 评论( loading... ) | 编辑| 举报| 收藏

    旧一篇:一道机考题,和大家分享 | 新一篇:用ajax实现仿CSDN下载评论的闪烁效果

    • 发表评论
    • 评论内容:
    •  
    Copyright © zengxie
    Powered by CSDN Blog