Clone an ArrayList : ArrayList « Collections Data Structure « C# / C Sharp






Clone an ArrayList

  


using System;
using System.Collections;

public class Starter {
    public static void Main(string[] argv) {

        ArrayList al1 = new ArrayList();
        foreach (string arg in argv) {
            al1.Add(int.Parse(arg));
        }
        al1.Sort();
        ArrayList al2 = (ArrayList)al1.Clone();
        for (int count = 0; count < al2.Count; ++count) {
            al2[count] = ((int)al2[count]) * 2;
        }
        foreach (int number in al2) {
            Console.WriteLine(number);

        }
    }
}


           
         
    
  








Related examples in the same category

1.Add items to ArrayList and use foreach loop to check
2.Add array to ArrayList
3.Remove range from ArrayList
4.CopyTo, ToArray(), ToArray(typeof(String))
5.Using foreach to loop through ArrayList and use Indexer of ArrayList
6.Check InvalidCastException when using foreach loop with ArrayList
7.Binary Search an ArrayList
8.Inserting into an ArrayList by index
9.Checks time needed for list operations using an ArrayList implementationChecks time needed for list operations using an ArrayList implementation
10.ArrayList Demo: hold classArrayList Demo: hold class
11.illustrates the use of ArrayList properties and methodsillustrates the use of ArrayList properties and methods
12.illustrates the use of an ArrayList that contains objects of the Car classillustrates the use of an ArrayList that contains objects of the Car class
13.illustrates the use of ArrayLists 2illustrates the use of ArrayLists 2
14.Convert an ArrayList into an arrayConvert an ArrayList into an array
15.Sort and search an ArrayListSort and search an ArrayList
16.Demonstrate ArrayListDemonstrate ArrayList
17.Search for the first occurrence of the duplicated value
18.Search for the first occurrence of the duplicated value in the last section of the ArrayList
19.Search for the first occurrence of the duplicated value in a section of the ArrayList
20.Search for the first occurrence of the duplicated value in a small section at the end of the ArrayList
21.Convert a ArrayList object to a array
22.Represents a loose abstraction of an arraylist, wheres the buffer array is available for public access.