Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 911391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:11:53+00:00 2026-05-15T17:11:53+00:00

After discovering lambda expressions, and their use as anonymous functions, I’ve found myself writing

  • 0

After discovering lambda expressions, and their use as anonymous functions, I’ve found myself writing a lot of more trivial events such as these:

txtLogin.GotFocus += (o, e) =>
{
    txtLogin.Text = string.Empty;
    txtLogin.ForeColor = SystemColors.ControlText;
};
txtLogin.LostFocus += (o, e) =>
{
    txtLogin.Text = "Login...";
    txtLogin.ForeColor = SystemColors.InactiveCaptionText;
};

I’ve also moved away from event handlers which just call other functions, replacing them with small lambdas which do the same:

backgroundWorker.DoWork += (o, e) => DatabaseLookup.Open(e.Argument as string);

I’ve found some similar questions addressing performance concerns and pointing out that you can’t remove them, but I haven’t found any addressing the simple question of is this a good idea?

Is the use of lambdas in such a way considered good form, or do more experience programmers look down on this? Does it hide event handlers in hard-to-find places, or does it do the code a service by reducing the number of trivial event handlers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:11:54+00:00Added an answer on May 15, 2026 at 5:11 pm

    It’s a perfectly reasonable idea – but in this particular case, I would use an anonymous method instead:

    txtLogin.LostFocus += delegate
    {
        txtLogin.Text = "Login...";
        txtLogin.ForeColor = SystemColors.InactiveCaptionText;
    };
    

    The benefit is that you don’t have to specify the parameters – which makes it clearer that you’re not using them. This is the only advantage that anonymous methods have over lambda expressions.

    The performance hit is almost always going to be negligible. The inability to remove them afterwards is a very real problem if you do need to be able to remove the handler, but I find that often I don’t. (Reactive Extensions has a nice approach to this – when you subscribe to an observable sequence, you’re given back an IDisposable which will remove the subscription if you call it. Very neat.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After discovering the Boost preprocessor's capabilities I found myself wondering: Is the C99 preprocessor
I am just learning how to use Terracotta after discovering it about a month
After doing research, I found that it is more recommended to save the image
After discovering about Javascript namespaces, I tried to implement them but I run into
After discovering on superuser that there is no current way to add syntax highlighting
After recently discovering how insanely long the .net 3.5 framework was to install I
After a long search I'm still confused about it although I found some related
I solved this myself, but I spent so long discovering such a simple solution,
after I did some research on the subject, I found that Windows Live stopped
After discovering that Sass doesn't have exponential abilities, I decided to make my own

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.