标题:小弟初学C#,有一程序不解!
取消只看楼主
andygdd
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-9-11
 问题点数:0 回复次数:1 
小弟初学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]
搜索更多相关主题的帖子: 初学 
2008-03-01 01:11
andygdd
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-9-11
得分:0 
不会吧,没有人帮我吗?
2008-03-01 17:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-201499-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.330958 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved