4

Sorry if this has been asked before, but I would like a concise answer on the differences between the following two usages. VS seems to accept both of them as valid code.

private static void doSomeWork()
{
   //do some work
}

public someClass()
{
   //Thread thread = new Thread(doSomeWork);
   //or
   //Thread thread = new Thread(new ThreadStart(doSomeWork));
}
Kang Min Yoo
  • 805
  • 1
  • 9
  • 20
  • 1
    Have a look at http://stackoverflow.com/questions/3360555/how-to-pass-parameters-to-threadstart-method-in-thread – Asif Mushtaq May 07 '12 at 12:32
  • Very similar to: http://stackoverflow.com/questions/2749868/new-eventhandlermethod-vs-method – CodesInChaos Aug 21 '12 at 17:04
  • possible duplicate of [C# Delegate Instantiation vs. Just Passing the Method Reference](http://stackoverflow.com/questions/2181282/c-sharp-delegate-instantiation-vs-just-passing-the-method-reference) – nawfal Jul 06 '14 at 20:27

1 Answers1

6

The only difference is that the first one doesn't work in C# 1. The compiler of C# 2 and later, translates the first one into the second one.

Method groups are implicitly convertible to delegate types with a compatible signature. This feature is called "(Implicit) method group conversion". Sometimes you need the second one to guide overload resolution, but that's not the case here.

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262