tags:

views:

31

answers:

1

i am new to c#. coming from mainly PHP background or basic VB.

i understand that IEnumerable<Customer> is something like a list of customer.

but what is Action<IEnumerable<Customer>, Exception>. an action of type IEnumerable<Customer> & Exception. doesnt seem to make too much sense to me.

+4  A: 

In C#, Action and Func are function pointers, you can pass them around just like any other object and you invoke them in exactly the same way that you call other functions. Essentially Action<IEnumerable<Customer>, Exception> means:

  • A function which returns void, and accepts two parameters of types IEnumerable<Customer> and Exception as an input.

This would be a compatible signature:

void DoStuff(IEnumerable<Customer> customer, Exception e) { ... }

Sometimes long generic signatures like the one you have can be cumbersome to work with, it can occasionally be nicer to move those params into a single object such as:

class CustomerContext {
    public IEnumerable<Customer> Customers { get; set; }
    public Exception Exception { get; set; }
}

At least then you can pass around an Action<CustomerContext>, which can save some typing and sanity :)

Juliet
(Of course, you could also declare a new [delegate type](http://msdn.microsoft.com/en-us/library/ms173171%28VS.80%29.aspx).)
Timwi