小弟初学C#,有一程序不解!
程序:public class Control
{
public delegate void SomeHandler(object sender, System.EventArgs e);
public event SomeHandler SomeEvent;
public Control()
{
this.SomeEvent += new SomeHandler(this.ProcessSomeEvent);
}
public void RaiseSomeEvent()
{
EventArgs e = new EventArgs();
Console.Write("Please input 'a':");
string s = Console.ReadLine();
if (s == "a")
{
SomeEvent(this, e);
}
}
private void ProcessSomeEvent(object sender, EventArgs e)
{
Console.WriteLine("hello");
}
}
class Container
{
private Control ctrl = new Control();
public Container()
{
ctrl.SomeEvent += new Control.SomeHandler(this.ResponseSomeEvent);
ctrl.RaiseSomeEvent();
}
public static void Main()
{
Container pane = new Container();
Console.ReadLine();
}
private void ResponseSomeEvent(object sender, EventArgs e)
{
Console.WriteLine("Some event occur!");
}
}
其输出:
please input 'a':a
hello
Some event occur!
问题是当输入a后为什么先输出hello,而不是Some event occur!呢?
望达人解答!!!![bc02]