

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Clone() method in C#
The Clone() method in C# is used to create a similar copy of the array.
Let us see an example to clone an array using the Clone() method −
Example
using System; class Program { static void Main() { string[] arr = { "one", "two", "three", "four", "five" }; string[] arrCloned = arr.Clone() as string[]; Console.WriteLine(string.Join(",", arr)); // cloned array Console.WriteLine(string.Join(",", arrCloned)); Console.WriteLine(); } }
Output
one,two,three,four,five one,two,three,four,five
Above, we have a string array −
string[] arr = { "one", "two", "three", "four", "five" };
With that, in a new string array, we have used the Clone() method with the as operator to clone the array −
string[] arrCloned = arr.Clone() as string[];
- Related Questions & Answers
- clone() method in Java
- Demonstrate the clone() method in Java
- Importance of clone() method in Java?
- The clone() method of CopyOnWriteArrayList method in Java
- What does the method clone() do in java?
- Clone IdentityHashMap in Java
- Clone HashMap in Java
- How to use the Clone() method of array class in C#?
- Clone an ArrayList in Java
- Clone a collection in MongoDB?
- When overriding clone method, why do we need to declare it as public in Java?
- How to clone an object in JavaScript?
- How to Clone a List in Java?
- How to Clone a Map in Java
- How to clone a GitHub repository?
Advertisements