×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# String.Clone() Method with Example

In this tutorial, we will learn about the String.Clone() method with its usage, syntax, and examples. By IncludeHelp Last updated : April 07, 2023

C# String.Clone() Method

The String.Clone() method is used to make a clone of a string object, it returns a reference to this instance of a String.

Syntax

String String.Clone();

Parameter(s)

  • None

Return Value

It returns a reference to this instance of a String.

Example

Input:
string str1 = "Hello IncludeHelp Readers";
    
Function call:
string str2 = (String)str1.Clone();

Output:
str1: Hello IncludeHelp Readers
str2: Hello IncludeHelp Readers

C# example to make a clone of a string using String.Clone() method

using System;
using System.Text;

namespace Test {
  class Program {
    static void Main(string[] args) {
      //string variable
      string str1 = "Hello IncludeHelp Readers";

      //making clone
      string str2 = (String) str1.Clone();

      //printing
      Console.WriteLine("str1: " + str1);
      Console.WriteLine("str2: " + str2);

      //hit ENTER to exit
      Console.ReadLine();
    }
  }
}

Output

str1: Hello IncludeHelp Readers
str2: Hello IncludeHelp Readers

Reference: String.Clone Method


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.