Reputation: 23
I'm wondering what's is the difference between this two uses of Add listener on c#. On my script, both are working. But I guess there should be a difference ? Thanks !
btn.onClick.AddListener(() => PickAPuzzle());
btn.onClick.AddListener (PickAPuzzle);
Upvotes: 0
Views: 912
Reputation: 46366
The two are identical, the first is using a slightly longer form of passing an explicit overload whereas the second is using a method group, where the compiler chooses the correct overload (see: What is a Method Group in C#?).
AddListener() is one and the same, and the delegates they receive are effectively the same. The difference is syntactical shorthand.
Upvotes: 1