Convert ArrayList to Array in CSharp

Description

The following code shows how to convert ArrayList to Array.

Example


using System; /* w w  w . jav  a  2  s. com*/
using System.Collections;
class MainClass
{
    public static void Main()
    {
        ArrayList list = new ArrayList(5);
        list.Add("B");
        list.Add("G");
        list.Add("J");
        list.Add("S");
        list.Add("M");

        object[] array2 = list.ToArray();

        foreach (string s in array2)
        {
            Console.WriteLine(s);
        }
     }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary