Possible Duplicate:
Why use “new DelegateType(Delegate)”?
What is the difference between new Thread(void Target()) and new Thread(new ThreadStart(void Target()))?
So I have been through a little bit of delegate and got the whole idea somehow.
Now, I see everywhere exemple like this:
public delegate void Deleg();
Deleg deleg = new Deleg(FunctionName);
deleg();
I would think this creates an delegate object with the function to point at being passed as parameter to the constructor.
Now, I can also do like this:
public delegate void Deleg();
public Deleg deleg;
deleg = FunctionName;
deleg();
This one seems to only create a reference and the address of the function is passed. This works just the same and has all the delegate functionalities.
But now, regardless of the fact I have one more line in the second exemple, do I actually lose or gain something out of the second since the first one is more popular on tutorials?
The gain is a little less typing. The compiler is smarter now than it was initially, so it can do the method group conversion implicitly which is why you don’t have to do
new Deleg(FunctionName)anymore.