Anonymous method trivia

Can you guess how many times will this console application output the current date?

class Program { private static Tubo tubo = new Tubo(); static void Main(string[] args) { One(); tubo.RaiseTubek(); Console.WriteLine("Finished"); Console.ReadLine(); } private static void One() { tubo.Tubek += delegate { Console.WriteLine(DateTime.Now); }; tubo.RaiseTubek(); } } public class Tubo { public event EventHandler Tubek; public void RaiseTubek() { if (Tubek != null) Tubek(this, EventArgs.Empty); } }

Comments (5) -

  • Mladen

    8/28/2007 11:52:56 PM | Reply

    51.6 times exactly! Smile

  • Mladen

    8/28/2007 11:55:16 PM | Reply

    without running this i'd say twice.
    if it's anything other than that, i have no idea why.

  • Bojan

    8/29/2007 1:17:07 AM | Reply

    Jup, twice...i tryed.... Smile

  • Mladen

    8/29/2007 10:06:06 AM | Reply

    so miha... what's the catch?
    give!!

  • Miha Markic

    8/29/2007 10:48:21 AM | Reply

    I am getting there - yes, it is printed twice as you guys guessed (and cheated Wink). But there is more to come.

Loading