CopyTo, ToArray(), ToArray(typeof(String)) : ArrayList : Collections Data Structure C# Source Code


Custom Search

C# Source Code » Collections Data Structure » ArrayList »

 

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);
            }
         }
    }

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Collections Data Structure
» ArrayList