.net - C# Delegate Instantiation vs. Just Passing the Method Reference -
I have a simple question: what is the benefit of creating a C # representative immediately after crossing the function reference ? What do I mean:
Why:
threads t = new thread (new threadstart (some objects. Some method));
When you can:
threads t = new thread (SomeObject.SomeMethod);
Both of my experiences will compile and work ... am I missing something?
Return method in method group SomeObject.SomeMethod
There is a method with and do not take any parameters so there is no difference. The reason for this is that Thread Start
is defined as delegation
zero
and takes no parameter and hence the method group < Code> Some Objects Some method to threadstart
. Thus, both the threads
are implementing the overload of the constructor.
The relevant section of the language specification is §6.6 (method group conversion).
I have a simple question: What is the benefit of creating the C # representative immediately after opposing the function reference?
So, here's just a correction of terminology. With
class MyObject {public zero some method () {}} MyObject someObject = new MyObject ();
The item marked by someObject.SomeMethod
is a method group. You can think of it as a set of overloaded methods which can be seen using the notation someObject.SomeMethod
.
Comments
Post a Comment