0

Im confused. The docs say a ThreadStart or ParametrizedThreadStart delegate is expected, but a method reference can be passed. How come it accepts a simple reference to a method, why is there no constructor signature that specifically determines this? Or is a delegate functionally identical to a method reference when it comes to type checking? Im kind of inexperienced when it comes to .net, and this is very confusing to me.

Thanks in advance.

  • One line of code worth few paragraphs sometimes... – Sinatr Jan 31 '17 at 12:37
  • When you pass the name of a function it will create a delegate to the function which inferes the params/return types from the function signature, so at the end the compiled code will be the same. – Gusman Jan 31 '17 at 12:38
  • 1
    Or maybe [this one](http://stackoverflow.com/q/6056983/1997232)? – Sinatr Jan 31 '17 at 12:44
  • That second suggestion is far better because it's discussing the implicit conversion of method groups to delegates which I think is what the OP is confused by. Alas, already closed linking to the wrong question. – Damien_The_Unbeliever Jan 31 '17 at 12:47
  • Thanks, that second question really nailed it. – Joseph Herraez Jan 31 '17 at 12:49

1 Answers1

0

A delegate is a "method reference" of sorts, and by definition a reference to a method is too. So the two are equivalent:

var thread = new Thread(new ThreadStart(MyMethod));
// or
var thread = new Thread(MyMethod); // Assuming Mymethod conforms to the right spec
Jamiec
  • 133,658
  • 13
  • 134
  • 193