I have the following code:
recognizer = new GestureRecognizer();
recognizer.Tapped += (args) =>
{
// Send an OnSelect message to the focused object and its ancestors.
if (FocusedObject != null)
{
FocusedObject.SendMessageUpwards("OnSelect",
SendMessageOptions.DontRequireReceiver);
}
};
I am working in a project for Unity and I am not that experienced with the syntax of this operation:
recognizer.Tapped += (args) =>
{
// Send an OnSelect message to the focused object and its ancestors.
if (FocusedObject != null)
{
FocusedObject.SendMessageUpwards("OnSelect",
SendMessageOptions.DontRequireReceiver);
}
I understand that Tapped is the event listener for taps. However, I don't understand the following things:
1) Why are they using a += operator to add a lambda function. How can you add a lambda function like that? I've always used += on primitive types.
2) Where does "args" come from?
3) When does that lambda function run?
+=is the syntax that adds an event listener. A lambda can be an event listener as long as it accepts the event's arguments+=is the syntax used to add event listeners to events. It's explained in the docs. That's not new syntax either, I think this was available since .NET 1.0