Use ArrayList.ToArray to create a strongly typed string array from the contents of the collection : ArrayList ToArray « Data Structure « C# / CSharp Tutorial






using System;
using System.Collections;

class MainClass
{
    public static void Main(string[] args)
    {
        // Create a new ArrayList and populate it.
        ArrayList list = new ArrayList(5);
        list.Add("B");
        list.Add("G");
        list.Add("J");
        list.Add("S");
        list.Add("M");

        string[] array3 = (string[])list.ToArray(typeof(String));

        Console.WriteLine("Array 3:");
        foreach (string s in array3) 
        {
            Console.WriteLine("\t{0}", s);
        }

    }
}
Array 3:
        B
        G
        J
        S
        M








11.24.ArrayList ToArray
11.24.1.Convert an ArrayList into an array
11.24.2.Use ArrayList.ToArray to create a strongly typed string array from the contents of the collection
11.24.3.Convert user-defined objects in an ArrayList to an array