ArrayList.Clone() Method is used to create a shallow copy of the specified ArrayList. A shallow copy of a collection copies only the elements of the collection irrespective of reference types or value types. But it does not copy the objects that the references refer to. The references in the new collection point to the same objects that the references in the original collection point to.
public virtual object Clone ();
Below programs illustrate the use of above-discussed method:
Elements of Original ArrayList: Geeks for Geeks 10 20 Elements of Cloned ArrayList: Geeks for Geeks 10 20
Elements of Original ArrayList: 10 20 30 40 50 Elements of Cloned ArrayList: 10 20 30 40 50 After Adding, Original ArrayList: 10 20 30 40 50 60 After Adding, Cloned ArrayList: 10 20 30 40 50 Reference Equals: False
- How to create a shallow copy of Hashtable in C#
- How to create a shallow copy of BitArray in C#
- C# | How to create a shallow copy of the BitArray
- How to create a shallow copy of SortedList Object in C#
- Shallow Copy and Deep Copy in C#
- C# | How to copy the entire ArrayList to a one-dimensional Array
- How to create the ArrayList in C#
- C# | Copy the elements of collection over a range of elements in ArrayList
- ArrayList in C#
- C# | Copy Constructor
- C# | Copy() Method
- C# | Array vs ArrayList
- C# | Add an object to the end of the ArrayList
- C# | ArrayList Class
- C# | Copy the Stack to an Array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.