object sender, MyEventArgs e 的实验

来源:互联网 发布:软件危机与软件工程 编辑:程序博客网 时间:2024/06/07 16:43

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

namespace ConsoleApplication20
{
    class MyEventArgs : EventArgs
    {
        private char keyChar;
        public MyEventArgs(char keyChar)
        {
            this.keyChar = keyChar;
        }
        public char KeyChar
        {
            get
            {
                return keyChar;
            }
        }
    }

    class A
    {
        public delegate void InputMonior(object sender, MyEventArgs e);
        public event InputMonior myInputMonior;
        public void run()
        {
            while (true)
            {
                if (Console.ReadLine() == "a")
                {
                    myInputMonior(this, new MyEventArgs('a'));
                }
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            A tt = new A();
            new Program(tt);
            tt.run();
        }
        void show(object sender, MyEventArgs e)
        {
            Console.WriteLine("Hello,World!");
            Console.WriteLine("捕捉到:{0}", e.KeyChar);
       
        }
        Program(A e)
        {
            e.myInputMonior += new A.InputMonior(this.show);
        }
    }
}

 这是自己做的关于object sender, MyEventArgs e的实验,发现C#没有想象的简单!我要加油了还有很多不大清楚,搞明白了在加注释吧

原创粉丝点击