An object reference is required for the non-static field, method, or property

The problem is that you attempting to access the non-static property Customers from within a static method.

I suspect what you want is this:

public void AllCustomers()
{
    // ...

(i.e. get rid of the static modifier)

Alternatively you can make both customers and the Customers members static too:

private static List<Customer> customers = new List<Customer>();

public static List<Customer> Customers
{
    get { return customers; }
    set { customers = value; }
}

Leave a Comment