C# ArrayList Clone

Description

ArrayList Clone creates a shallow copy of the ArrayList.

Syntax

ArrayList.Clone has the following syntax.


public virtual Object Clone()

Returns

ArrayList.Clone method returns A shallow copy of the ArrayList.

Example


using System;/*from   w w w  . jav  a2  s.c om*/
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);

        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack