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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:52:32+00:00 2026-05-14T00:52:32+00:00

So I read MSDN and Stack Overflow. I understand what the Action Delegate does

  • 0

So I read MSDN and Stack Overflow. I understand what the Action Delegate does in general but it is not clicking no matter how many examples I do. In general, the same goes for the idea of delegates. So here is my question. When you have a function like this:

public GetCustomers(Action<IEnumerable<Customer>,Exception> callBack)
{
}

What is this, and what should I pass to it?

  • 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-14T00:52:32+00:00Added an answer on May 14, 2026 at 12:52 am

    it expects a function that takes IEnumerable and Exception and returns void.

    void SendExceptionToCustomers(IEnumerable<Customer> customers, Exception ex) {
       foreach(var customer in customers)
          customer.SendMessage(ex.Message);
    }
    
    GetCustomers(SendExceptionToCustomers);
    

    btw, GetCustomers seems like a terrible name for this function — it’s asking for an action, so its more like DoSomethingToCustomers

    EDIT in response to comment


    Ok Makes sense, So now why even bother with having a GetCustomer Function? Can’t I do that same thing with your function if i Just rename it GetCustomer?

    Well, what’s happening here is the caller can specify some action. Suppose GetCustomers is implemented like this:

    public void GetCustomers(Action<Enumerable<Customer>, Exception> handleError) {
        Customer[] customerlist =  GetCustomersFromDatabase();
        try {
            foreach(var c in customerList) 
                c.ProcessSomething()
        } catch (Exception e) {
            handleError(customerList, e);
        }
    }
    

    then you could call Getcustomers from somewhere on a commandline program, and pass it

    GetCustomers((list, exception) => { 
        Console.WriteLine("Encountered error processing the following customers");
        foreach(var customer in list) Console.WriteLine(customer.Name);
        Console.WriteLine(exception.Message);
    }); 
    

    while you could call GetCustomers from a remote application, for example, and pass it

    Getcustomers((list, exception) => { 
        // code that emails me the exception message and customer list
    })
    

    Also, Slak’s comment suggests another reason for delegate parameter — GetCustomers does retrieve the customers, but asynchronously. Whenever it is done retrieving the customers, it calls the function you give it with either the customerlist or an exception, if an exception occurred.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could use a variable to make the calculation and… May 15, 2026 at 6:57 am
  • Editorial Team
    Editorial Team added an answer This is called Constrained Delegation. Basically what that means is… May 15, 2026 at 6:57 am
  • Editorial Team
    Editorial Team added an answer Well, for one thing .data() doesn't have a terminal \0.… May 15, 2026 at 6:57 am

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.