Create a shallow copy(clone) of the ArrayList in CSharp

Description

The following code shows how to create a shallow copy(clone) of the ArrayList.

Example


using System;/*from www. j  a  va2 s .  c o m*/
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);

        }
    }
}




















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary