CopyTo, ToArray(), ToArray(typeof(String))
using System;
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");
string[] array1 = new string[list.Count];
list.CopyTo(array1, 0);
object[] array2 = list.ToArray();
string[] array3 = (string[])list.ToArray(typeof(String));
foreach (string s in array1)
{
Console.WriteLine(s);
}
foreach (string s in array2)
{
Console.WriteLine(s);
}
foreach (string s in array3)
{
Console.WriteLine(s);
}
}
}
Related examples in the same category