Create a class with array of objects.
- by Bi
Hi
Code below defines a ChargeCustomer class that contains an array of type "customers". I want to be able to create an object with either 1 "customer" or 2 "customers" based on the constructor parameters. Is this the right way to do so in C#:
public class ChargeCustomer
{
private Customer[] customers;
public ChargeCustomer( string aName, string bName, int charge )
{
customers = new Customer[2];
customers[0] = new Customer(aName, charge);
customers[1] = new DropBox(bName, charge);
}
public ChargeCustomer( string bName, int charge )
{
customers = new Customer[1];
customers[0] = new Customer( bName, charge );
}
}
Thanks!