Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread What is the difference between

What is the difference between

Thread t = new Thread (new ThreadStart (Go));

and

Thread t = new Thread (Go);

where Go is a method

like image 981
Kuttan Sujith Avatar asked Sep 21 '26 18:09

Kuttan Sujith


2 Answers

The only time there is a difference is if Go is a method-group that could match multiple Thread constructor overloads - for example, because there is a constructor for both ThreadStart and ParameterizedThreadStart, the following methods would make the new Thread(Go) version ambiguous:

static void Go() { }
static void Go(object val) { }

The new Thread (new ThreadStart (Go)) disambiguates that by explicitly declaring the delegate type, but: other than that they are identical, on C# 2 or above. Note: prior to C# 2, the shorter version was not legal syntax.

like image 171
Marc Gravell Avatar answered Sep 24 '26 08:09

Marc Gravell


None. They are the same thing.

The documentation states this:

Visual Basic and C# users can omit the ThreadStart or ParameterizedThreadStart delegate constructor when creating a thread. [...] In C#, simply specify the name of the thread procedure. The compiler selects the correct delegate constructor.

like image 37
RePierre Avatar answered Sep 24 '26 06:09

RePierre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!