This method is used to create a shallow copy of the Queue. It just creates a copy of the Queue. The copy will have a reference to a clone of the internal elements but not a reference to the original elements.
Syntax: public virtual object Clone ();
Return Value: The method returns an Object which is just the shallow copy of the Queue.
Example 1: Let’s see an example without using a Clone() method and directly copying a Queue using assignment operator ‘=’. In the below code, we can see even if we Dequeue() elements from myQueue2, contents of myQueue is also changed. This is because ‘=’ just assigns the reference of myQueue to myQueue2 and does not create any new Queue. But Clone() creates a new Queue.
Class Noida UP
Example 2: Here myQueue is unchanged.
Geeks Class Noida UP
- Difference between Method Overriding and Method Hiding in C#
- C# | Trim() Method
- C# | Remove() Method
- Decimal.Add() Method in C#
- Anonymous Method in C#
- C# | Replace() Method
- C# | Insert() Method
- C# | CopyTo() Method
- C# | Math.Max() Method
- C# | Uri.IsHexEncoding() Method
- jQuery | is() Method
- TimeSpan.Add() Method in C#
- Extension Method in C#
- C# | Uri.GetHashCode() Method
- C# | Uri.FromHex() Method
- Stack.Contains() Method in C#
- Stack.Pop() Method in C#
- C# | ToUpper() Method
- C# | ToLower() Method
- C# | String.Contains() 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 firstname.lastname@example.org. 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.