help creating an object

sde

Well-known member
Joined
Aug 28, 2003
Messages
160
Location
us.ca.fullerton
i have a customer object and a phone object. the phone object is a property of the customer object in the form of an array.

im not sure how to explain this, but look at this code:
Code:
// if the phone array contained 2 elements
// this is how i could access the phone numbers
MessageBox.Show(Customer.Phone[0].Text);
MessageBox.Show(Customer.Phone[1].Text);

// add a phone to the array with this call
Customer.Phone.Add("8005551212");

how do i create that "Add" method to Phone without having to reference a specific instance of that phone array?

i mean:

Phone.Add vs. Phone[0].Add

does this make sense?
 
if you want to do it in that way then you have to add a parameter for the index like

C#:
public void Add(string PhoneNumber, int index)
{
    Customer.Phone[index].Text = PhoneNumber; 
}
 
thanks, but im still a little confused.

is there any way to put this Add method in the Phone class though? with your example, you reference the customer object.

hmm .. would i pass the customer object in by reference then too?
 
If instead of using an array for the phonelist you used either a ArrayList or inherit your own collection from ArrayList then you would have an Add method.
 
You wouldnt add the Add method to the Phone class, since
it already has one. Instead, you would inherit some type of
collection and overload the Add method, like PlausiblyDamp
mentioned.
 
well im coding this in avr.net for as/400 access, but you get the idea:
Code:
	dclfld CustomerID 	type(*string) access(*public)
	dclfld AreaCode		type(*string) access(*public)
	dclfld Prefix		type(*string) access(*public)
	dclfld Suffix		type(*string) access(*public)
	dclfld Extention	type(*string) access(*public)
	dclfld PhoneType	type(*string) access(*public) // HMVC,HMFX,BSVC,BSFX,CELL,UNKN

i like the ArrayList idea. could i override the Add method of that array list ? the add method i want to impliment will add it to the database when it adds the number to the collection.

at this point, i think it is best if i make a method in the customer class to add a phone number, and then just refresh the data. it just seemed logical to attempt it the other way.

thanks for the help!
 
Back
Top