Code Trivia #6

Posted by João Angelo on Exceptional Code See other posts from Exceptional Code or by João Angelo
Published on Mon, 07 Feb 2011 07:32:42 +0000 Indexed on 2011/02/07 15:32 UTC
Read the original article Hit count: 454

Filed under:
|
|

It’s time for yet another code trivia and it’s business as usual. What will the following program output to the console?

using System;
using System.Drawing;
using System.Threading;

class Program
{
    [ThreadStatic]
    static Point Mark = new Point(1, 1);

    static void Main()
    {
        Thread.CurrentThread.Name = "A";

        MoveMarkUp();

        var helperThread = new Thread(MoveMarkUp) { Name = "B" };

        helperThread.Start();
        helperThread.Join();
    }

    static void MoveMarkUp()
    {
        Mark.Y++;

        Console.WriteLine("{0}:{1}", Thread.CurrentThread.Name, Mark);
    }
}

© Exceptional Code or respective owner

Related posts about .NET

Related posts about c#