Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# String Insert() Method
Next article icon

C# String Clone() Method

Last Updated : 13 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In C#, the Clone() method is a String method. It is used to clone the string object, which returns another copy of that data. In other words, it returns a reference to this instance of String. The return value will be only another view of the same data. The Clone() method is called directly on the current String instance. This method will not take any parameters. Some important characteristics of the clone method are,

  • This method is part of the ICloneable interface.
  • Strings are immutable, so we cannot change their values that's why we need to use the Clone() method.
  • The clone() method created a Shallow copy of the object ( They refer to the same memory).
  • Strings are immutable, so the Clone() method creates a new identical string object with the same reference.

Example 1: Demonstration of String Clone() method.

csharp
// C# program to illustrate  // Clone() method using System; class Geeks  {     public static void Main(string[] args)     {         string s = "GeeksforGeeks";          // Cannot implicitly convert          // type object to the string.         // So explicit conversion          // using Clone() method         string clone = (String)s.Clone();                 // Displaying both the string         Console.WriteLine("Original String : {0}", s);         Console.WriteLine("Clone String : {0}", clone);     } } 

Output
Original String : GeeksforGeeks Clone String : GeeksforGeeks 

Syntax of String Clone() Method

public object Clone()

Return Type: This method returns a reference of an original string of type System.Object.

Example 2: Demonstration of how the object created by the Clone() method shares the same reference (shallow copy).

C#
using System;  class Geeks {     public static void Main()     {         string s = "Hello, World!"; 		string s2 = "Hello, World!";          		// using the string clone method         string Clone = (string)s.Clone();  		Console.WriteLine("Is s and s2 sharing the same memory location: {0}", 		 object.ReferenceEquals(s, s2)); 		Console.WriteLine("Is s and Clone sharing the same memory location: {0}", 		 object.ReferenceEquals(s, Clone));           } } 

Explanation: In the above example, we use the Clone() method to clone a string object. And check their memory reference. We know that the strings are immutable in C# so if we create another string with the same value it also shares the same reference but if we modify the Clone object it will not affect the original object because it will create a new string instance in that case.

Important Points:

  • The String.Clone() method creates a shallow copy of a string object but due to its Immutaballity. If we make any modification to the clone object does not reflect on the original object
  • It behaves like a deep copy but internally it is shallow copy the difference between deep and shallow copy covered in this article.

Next Article
C# String Insert() Method

M

Mithun Kumar
Improve
Article Tags :
  • C#
  • CSharp-method
  • CSharp-string

Similar Reads

  • C# String CopyTo() Method
    In C#, the CopyTo() is a method of String Class. It is used to copy a specified number of characters from a specified position in the string and it copies the characters of this string into an array of Unicode characters. Example 1: Using the CopyTo() method to copy characters from a string to a cha
    3 min read
  • C# String Insert() Method
    The Insert() method in C# is a part of the String class. It is used to insert a new string at a specified index position and return a new string with the inserted string value. This method does not make the changes in the original string because strings are immutable in C#. It returns a new modified
    3 min read
  • StringBuilder.CopyTo Method in C#
    This method is used to copy the characters from a specified segment of this instance to a specified segment of a destination Char array. Syntax: public void CopyTo (int sourceIndex, char[] destination, int destinationIndex, int count); Parameters: sourceIndex: It is the starting position in this ins
    2 min read
  • C# | CharEnumerator.ToString() Method
    CharEnumerator.ToString() Method is used to get a string that represents the current object. It is inherited from the Object Class. Syntax: public virtual string ToString(); Return Value: This method returns a string which represents the current CharEnumerator object. Below are the programs to illus
    2 min read
  • C# String Replace() Method
    In C#, the Replace() method is used to replace all occurrences of a specified substring or character in a string with another substring or character. This method is particularly useful for string manipulation tasks, such as formatting or cleaning up data. Example 1: Using Replace() method to replace
    3 min read
  • C# | Copy() Method
    In C#, Copy() is a string method. It is used to create a new instance of String with the same value for a specified String. The Copy() method returns a String object, which is the same as the original string but represents a different object reference. To check its reference, use assignment operatio
    2 min read
  • C# String Class
    In C#, a string is a sequence of Unicode characters or an array of characters. The range of Unicode characters will be U+0000 to U+FFFF. The array of characters is also termed as the text. So the string is the representation of the text. A string is represented by a class System.String. The String c
    9 min read
  • C# | CharEnumerator.Clone() Method
    CharEnumerator.Clone Method is used to create a copy of the current CharEnumerator object. This is useful for saving the current state while iterating through a String object. Syntax: public object Clone (); Return Value: This method returns an Object which is a copy of the current CharEnumerator ob
    2 min read
  • C# | TrimStart() and TrimEnd() Method
    Prerequisite: Trim() Method in C# In C#, TrimStart() & TrimEnd() are the string methods. TrimStart() method is used to remove the occurrences of a set of characters specified in an array from the starting of the current String object. TrimEnd() method is used to remove the occurrences of a set o
    3 min read
  • C# | ToCharArray() Method
    In C#, ToCharArray() is a string method. This method is used to copy the characters from a specified string in the current instance to a Unicode character array or the characters of a specified substring in the current instance to a Unicode character array. This method can be overloaded by changing
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences