Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to combine to lambdaas which have the same body?

myEntry.Unfocused += async (s, e) =>
                {
                   // Same code
                }

myButton.Clicked += async (s, e) =>
                {
                   // Same code
                }

Is it possible to combine these tow lambdas in order to avoid maintaining the same code twice?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

These events are effectively assigning a method to call once invoked. As long as the signature matches, you can point it directly at a named method

myEntry.Unfocused += OnEvent;
myButton.Clicked += OnEvent;

private async Task OnEvent(object sender, EventArgs args)
{
    // Do stuff here
}

Just ensure the return type is correct.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading