sde Posted February 2, 2004 Posted February 2, 2004 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. i'm not sure how to explain this, but look at this 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? Quote codenewbie
NK2000 Posted February 2, 2004 Posted February 2, 2004 if you want to do it in that way then you have to add a parameter for the index like public void Add(string PhoneNumber, int index) { Customer.Phone[index].Text = PhoneNumber; } Quote
sde Posted February 2, 2004 Author Posted February 2, 2004 thanks, but i'm 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? Quote codenewbie
Administrators PlausiblyDamp Posted February 2, 2004 Administrators Posted February 2, 2004 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
NK2000 Posted February 2, 2004 Posted February 2, 2004 maybe you show us your existing phone class then we could add it Quote
*Experts* Bucky Posted February 2, 2004 *Experts* Posted February 2, 2004 You wouldn't 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. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
sde Posted February 2, 2004 Author Posted February 2, 2004 well i'm coding this in avr.net for as/400 access, but you get the idea: 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! Quote codenewbie
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.