Jump to content
Xtreme .Net Talk

converting an arraylist to an array of objects inside of it


Recommended Posts

Posted

I am writting a method which returns an array of phone numbers. the phone numbers are their own object.

 

for reasons beyond my control, i need to build the array of phone numbers in an array list.

 

i now have an ArrayList of Phone objects.

 

is it possible to convert the ArrayList to a Phone array without running a foreach loop?

public Phone[] GetPhoneNumbers(string CustomerID)
{

 ...
 ArrayList PhoneArrayList = new ArrayList();

 while(reader.Read)
 {
   Phone phoneItem = new Phone();
   phoneItem.AreaCode = reader[0].ToString();
   phoneItem.Prefix = reader[1].ToString();
   phoneItem.Suffix = reader[2].ToString();
   phoneItem.Ext = reader[3].ToString();

   PhoneArrayList.Add(phoneItem);
 }

 Phone[] PhoneNumbers = new Phone[] { };

 // here is where i need to convert the ArrayList
 // to  Phone[] array
 
 return PhoneNumbers;
}

any insight would be greatly appreciated.

 

thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...