converting an arraylist to an array of objects inside of it

sde

Well-known member
Joined
Aug 28, 2003
Messages
160
Location
us.ca.fullerton
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?
Code:
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
 
Back
Top