Hi,
I'm building an application where I've defined a custom class Customer.
Customer can have many phones (defined by phoneType and phoneNumber). I want
to check that a phoneNumber is not already present in customer phones. So
i've build a PhoneCollection class inheriting for List<Phoneand defined an
Add method to check if the phoneNumber already exists. Then I added the
PhoneCollection to Customer properties.
Everything works fine, and I can add new phones to customer using
cust.Phones.Add("1234") but Customer.Phones has Count=0 and if I look at it
in the debugger the phones are inside rawData (??). Strange thing is that if
I use customer.Phones[i] i got the i phone object!
What am I missing?? Below you can find the classes used.
Any help is welcome!
Bye,
Stefano
public class Customer
{
private String id;
private readonly PhoneCollection phones = new PhoneCollection();
public Customer(string id)
{
this.id = id;
}
public PhoneCollection Phones
{
get
{
return this.phones;
}
}
}
public class Phone
{
private string id;
private string ownerId;
private int phoneType;
private string phonenumber;
public Customer(string id)
{
this.id = id;
}
public int PhoneType
{
get{return phoneType;}
set{phoneType = value;}
}
public string PhoneNumber
{
get{return phoneNumber;}
set{phoneNumber = value;}
}
}
public class PhoneCollection: List<Phone>
{
private List<Phonem_Phones = new List<Phone>();
public PhoneCollection()
{
m_Phones.Capacity = 10;
}
public void Add(string phoneNumber)
{
//Here I add a new Phone to m_Phones if the phoneNumber is not present
}
}