About Me

My photo
Northglenn, Colorado, United States
I'm primarily a BI Developer on the Microsoft stack. I do sometimes touch upon other Microsoft stacks ( web development, application development, and sql server development).

Tuesday, April 11, 2006

Old, but new to me: C# will this compile?

From: http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx

using System;
using System.Threading;

public class Class1
{
   public static void Main ()
   {
      new Thread(delegate
         {
            Console.WriteLine("On another thread");
         }).Start();
   }
}

I couldn't see why it could ever worked, but then looking at his solutions http://blogs.msdn.com/brada/archive/2004/12/27/332863.aspx

I see why I didn't like it. I would have used the first version of his solution:

new Thread(
delegate ()
   {
      Console.WriteLine("On another thread");
   }
).Start();

since it looks like the way a delegate would be initialized and a function that a thread would call.

No comments: