Possible Duplicate:
C# Lambda ( => )
For instance
Messenger.Default.Register<AboutToCloseMessage>(this, (msg) =>
{
if (msg.TheContainer == this.MyContainer) // only care if my container.
{
// decide whether or not we should cancel the Close
if (!(this.MyContainer.CanIClose))
{
msg.Execute(true); // indicate Cancel status via msg callback.
}
}
});
The
=>Operator is used for Lambda Expressions.
http://msdn.microsoft.com/en-us/library/bb397687.aspx
It allows you to define an anonymous function "on the fly" and can be used to create delegates or expression tree types.
It is a lambda, it allows you to create a function easily.
in your example you can also write:
Messenger.Default.Register<AboutToCloseMessage>(this, delegate(Message msg)
{
if (msg.TheContainer == this.MyContainer) // only care if my container.
{
// decide whether or not we should cancel the Close
if (!(this.MyContainer.CanIClose))
{
msg.Execute(true); // indicate Cancel status via msg callback.
}
}
});
or even
Messenger.Default.Register<AboutToCloseMessage>(this, foobar);
// somewhere after //
private void foobar(Message msg)
{
if (msg.TheContainer == this.MyContainer) // only care if my container.
{
// decide whether or not we should cancel the Close
if (!(this.MyContainer.CanIClose))
{
msg.Execute(true); // indicate Cancel status via msg callback.
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With