This method is used to create a shallow copy of the Stack. It just creates a copy of the Stack. The copy will have a reference to a clone of the internal data array but not a reference to the original internal data array.
Syntax: public virtual object Clone ();
Return Value: The method returns an Object which is just the shallow copy of the Stack.
Example 1: Let’s see an example without using a Clone() method and directly copying a Stack using assignment operator ‘=’. In the below code, we can see even if we Pop() elements from myStack2, contents of myStack is also changed. This is because ‘=’ just assigns the reference of myStack to myStack2 and does not create any new Stack. But Clone() creates a new Stack.
Java C++ C
4th Element 3rd Element 2nd Element 1st Element
- Difference between Method Overriding and Method Hiding in C#
- C# | Uri.IsBaseOf(Uri) Method
- jQuery | before() Method
- Queue.Contains() Method in C#
- C# | IsNullOrEmpty() Method
- C# | Random.Next() Method
- C# | Uri.IsWellFormedOriginalString() Method
- jQuery | off() Method
- C# | Math.Min() Method
- C# | Math.Max() Method
- C# | Uri.ToString() Method
- Main Method in C#
- C# | SortedDictionary.Add() Method
- C# | Math.Abs() Method | Set - 1
- C# | Math.Exp() Method
- C# | Math.Abs() Method | Set - 2
- C# | Math.Log() Method
- jQuery | die() Method
- C# | Method Parameters
- C# | Math.Tan() Method
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.