Reputation: 69
Whats the difference between the below two pieces of code?
Foo parameter = // get parameter value
Thread thread = new Thread(new ParameterizedThreadStart(DoMethod));
thread.Start(parameter);
Foo parameter = // get parameter value
Thread thread = new Thread(DoMethod);
thread.Start(parameter);
private void DoMethod(object obj)
{
Foo parameter = (Foo)obj;
// ...
}
Upvotes: 2
Views: 63
Reputation: 292425
There's no difference. The compiler implicitly converts new Thread(DoMethod)
to new Thread(new ParameterizedThreadStart(DoMethod))
. Implicit conversion of a method group to a delegate with a compatible signature was introduced in C# 2; before that, you had to use the explicit form.
Upvotes: 3