zoukankan      html  css  js  c++  java
  • C#中,两个事件的叠加,结果会如何?

    前段参加了个面试,C#中,两个事件叠加,如下

    t.EventTest += delegate { Console.WriteLine("111"); };
    t.EventTest += delegate { Console.WriteLine("222"); };

    其输出结果会是什么样的? 还是测试一下吧:

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

    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    Test1 t = new Test1();
    t.EventTest += delegate { Console.WriteLine("111"); };
    t.EventTest += delegate { Console.WriteLine("222"); };

    t.StarEvent();
    }
    }
    class Test1
    {
    public event EventHandler EventTest;
    public void StarEvent()
    {
    if (this.EventTest != null)
    this.EventTest(this, null);
    }
    }
    }

    最终,输出结果为
    111
    222

    看来,两个事件的叠加,效果也是叠加的!

  • 相关阅读:
    POJ 2486
    奇怪的电梯
    穿越泥地(mud)
    救援行动(save)
    As Fast As Possible
    Connecting Universities
    They Are Everywhere
    Cells Not Under Attack
    吃饭
    花店橱窗(flower)
  • 原文地址:https://www.cnblogs.com/skywind/p/712169.html
Copyright © 2011-2022 走看看