Search Chirayu Software Solutions Blog

Wednesday, March 19, 2014

Convert ArrayList to String Array

using System;
using System.Collections;

class Program
{
    static void Main()
    {
 //
 // Create an ArrayList with 4 strings.
 //
 ArrayList list = new ArrayList();
 list.Add("flora");
 list.Add("fauna");
 list.Add("mineral");
 list.Add("plant");
 //
 // Convert ArrayList to array.
 //
 string[] array = list.ToArray(typeof(string)) as string[];
 //
 // Loop over array.
 //
 foreach (string value in array)
 {
     Console.WriteLine(value);
 }
    }
}

Output

flora
fauna
mineral
plant
Post a Comment