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); } }
51.6 times exactly! ๐
without running this i’d say twice.
if it’s anything other than that, i have no idea why.
Jup, twice…i tryed…. ๐
so miha… what’s the catch?
give!!
I am getting there – yes, it is printed twice as you guys guessed (and cheated ;-)). But there is more to come.