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#没有想象的简单!我要加油了。还有很多不大清楚,搞明白了在加注释吧