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 846119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:33:49+00:00 2026-05-15T06:33:49+00:00

I see increasing use of the delegate types offered in the System namespace (

  • 0

I see increasing use of the delegate types offered in the System namespace (Action<T>; Predicate<T> etc). As these are delegates, my understanding is that they should be used where we have traditionally used delegates in the past (asynchronous calls; starting threads, event handling etc). Is it just preference or is it considered practice to use these delegate types in scenarios such as the below; rather than using calls to methods we have declared (or anonymous methods):

public void MyMethod()
{
      Action<string> action = delegate(string userName
      {
            try
            {
               XmlDocument profile = DataHelper.GetProfile(userName);
               UpdateMember(profile);
            }
            catch (Exception exception)
            {
               if (_log.IsErrorEnabled) _log.ErrorFormat(exception.Message);
               throw (exception);
            }
      };

      GetUsers().ForEach(action);
}

At first, I found the code less intuitive to follow than using declared or anonymous methods. I am starting to code this way, and wonder what the view are in this regard. The example above is all within a method. Is this delegate overuse?

  • 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-15T06:33:49+00:00Added an answer on May 15, 2026 at 6:33 am

    For a simple foreach loop, I would prefer the normal language construct – see this blog post for Eric Lippert’s view. I think the use of a delegate here is somewhat gratuitous.

    In other cases – particularly with LINQ – it makes a lot of sense.

    Delegates are a nice way of allowing specialization without the overhead of declaring and implementing an interface or deriving from a type in order to override methods… but everything in moderation, of course. If you’ve got several methods to implement (and you really want to specify behaviour for all of them) then an interface makes more sense. If you’re genuinely creating a specialized type then deriving and overriding make sense. If you’re wanting a strategy pattern, however, then delegates work very neatly.

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

Sidebar

Related Questions

See the question. I want to see the methods and classes offered by a
See: Understanding Pointers In many C flavoured languages, and some older languages like Fortran,
What are some iPhone or Android applications that use SMS as their primary means
I have a code that runs on an embedded system and it has to
I see an ever increasing number of users signing up on my site to
I'm profiling my application using VisualVM and I see that the heap size increased
I see that with -Xmx2g, the peak memory reaches 1G and does major collections
I thought that I could use SimpleDB to take care of the most challenging
One thing I see in some DDD enterprise apps that I work on, is
I want to see is fragmentation the reason of increasing memory usage of my

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.