Saturday 8 October 2011

How to convert ArrayList to Array


Question arises that how to convert array list to array . below are simple code to convert Arraylist to array
Simple Answer are given below
using System;
using System.Collections;


class Program
{
    static void Main()
    {
        ArrayList arrList = new ArrayList();


        int[] arrToConvert = new int[] {};


        //Add some value to ArrayList of type integer


        arrList.Add(1);


        arrList.Add(2);


        arrList.Add(3);


        arrList.Add(4);


        //Now convert ArrayList to array


        arrToConvert = (int[])arrList.ToArray(typeof(Int32));


        foreach(int i in arrToConvert )
        {
            Console.WriteLine(i);
            
        }
     
            Console.ReadLine();
    }
}


No comments:

Post a Comment