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

  • Home
  • SEARCH
  • 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 522805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:23:32+00:00 2026-05-13T08:23:32+00:00

Is there any best practice with respect to coding style with respect to explicit

  • 0

Is there any best practice with respect to coding style with respect to explicit use of the delegate keyword instead of using a lambda?

e.g.

new Thread(() =>
{
    // work item 1
    // work item 2
}).Start();

new Thread(delegate()
{
    // work item 1
    // work item 2
}).Start();

I think the lambda looks better. If the lambda is better style, what’s the point of having a delegate keyword, other than for the fact that it existed before lambdas were implemented?

  • 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-13T08:23:32+00:00Added an answer on May 13, 2026 at 8:23 am

    Lambda syntax is much more generalised, and the designers have said that they’d ideally remove the old overlapping syntaxes (dont have a citation, but it’s probably Eric Lippert or Jon Skeet in a book or a podcast).

    But delegate allows you to ignore parameters, e.g.:

    object.Event += delegate { };
    

    versus having to say:

    object.Event += (sender,args) => { };
    

    which can be very useful in large argument lists and/or to make the code more resilient to refactoring.

    EDIT: As pointed out by Yann Schwartz in another answer (now unfortunately deleted), a very neat usage of this trick is in order to provide a default hander for an event using the Null Object pattern:-

    class MyClassThatFiresWithoutTheTrick
    {
        public event EventHandler MyEvent; // implicit = null
    
        // Need a method to keep this DRY as each fire requires a null check - see Framework Design Guidelines by Abrams and Cwalina
        protected virtual void OnMyEvent()
        {
            // need to take a copy to avoid race conditions with _removes
            // See CLR via C# 3rd edition p 264-5 for reason why this happens to work
            //var handler = MyEvent;
            // BUT THIS is the preferred version
            var handler = Interlocked.CompareExchange( ref MyEvent, null, null);
            // Need to do this check as it might not have been overridden
            if( handler == null)
                return;
            handler( this, EventArgs.Empty );
        }
    }
    
    class MyClassThatFiresWithTheTrick
    {
        public event EventHandler MyEvent = delegate{};
    
        protected virtual void OnMyEvent()
        {
            MyEvent( this, EventArgs.Empty );
        }
    }
    

    (though what you might often end up doing is an Inline Method of OnMyEvent, making the code even shorter again.)

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

Sidebar

Ask A Question

Stats

  • Questions 261k
  • Answers 261k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Nicest would be to wrap it in a reuseable custom… May 13, 2026 at 11:30 am
  • Editorial Team
    Editorial Team added an answer Like this: from c in db.Company group c by c.Name… May 13, 2026 at 11:30 am
  • Editorial Team
    Editorial Team added an answer Using this.Dispatcher.BeginInvoke is necessary to move code execution on the… May 13, 2026 at 11:30 am

Related Questions

I'm aware that in WPF you want to keep the sizes of controls as
I have a colleague in my company whose opinions I have a great deal
Our application uses a topic to push message to a small set of subscribers.
I wanted to know what the community considers the best practices in respect to
I'm in the process of reviewing a code base (~20K LOC) and trying to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.