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?
it expects a function that takes IEnumerable and Exception and returns void.
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
Well, what’s happening here is the caller can specify some action. Suppose GetCustomers is implemented like this:
then you could call Getcustomers from somewhere on a commandline program, and pass it
while you could call GetCustomers from a remote application, for example, and pass it
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.