How geeks pass the time

As I mentioned earlier, I was at the Visual Studio/SQL Server/BizTalk product launch in Ottawa yesterday. I was lucky enough to be included I love getting a chance to talk to people who are just getting into .NET 2.0. I have been working with it on a daily basis for more than 6 months, to the point where I almost forget whas VS 2003 is like. Answering questions helps put my world back into perspective.

But it's not all talk at this sort of event. There is a fair bit of down time while most of the people are in sessions and there is no one to ask us questions. And when a bunch of geeks get bored, you know the results are not going to be pretty.  One of my co-experts, Richard Lander, presented the following challenge: http://hoser.lander.ca/PermaLink,guid,20c75894-5947-4a62-a9c6-01b14516ecf8.aspx

Make sure that you give the code a try. I can pretty much guarantee that the number of people who will guess correctly will be incredibly small. After all, Richard is on the CLR team (and smart to boot) and he wasn't jumping up and down with the answer. Even after seeing the results, those of us in the room were scratching our heads looking for the reason. So give it your best shot and let me what you think and why.

Comments

  • bruce November 12, 2005 8:13 PM


    The answer becomes clear if you modify the delegate to show the value of i before you sleep the thread.

    Thread t = new Thread(delegate() { Console.WriteLine("Starting" + i); Thread.Sleep(10); Console.WriteLine(i); });

    The value of i is bound to each of the calls to WriteLine when the individual methods are executed, not when the delegate begins execution.

Leave a Comment

(required) 
(optional)
(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS