C# String Copy() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In C#, String.Copy() creates another string instance that holds the same characters. In modern .NET it is obsolete, because a normal assignment is usually enough.

You pass one string. It is required. The result is a new string with the same text.

Syntax

Pass the string to copy. Start with this call.

C#
string copy = string.Copy(text);
CallWhat it does
string.Copy(text)Creates another string instance with the same characters.

This is a static method. Prefer a normal assignment unless you have a rare reason to force a separate instance.

Library declarations
C#
public static string Copy(string str);

Parameters

ParameterDescription
strRequired. The string to copy.

Return Value

Return ValueDescription
New stringAnother instance with the same text.

C# Examples

Example 1 — Basic Copy()

Duplicate a greeting into a new string and confirm the text matches.

C#
using System;

class Program {
    static void Main() {
        string original = "Hello, C#";
        string duplicate = string.Copy(original);

        Console.WriteLine($"Original:  {original}");
        Console.WriteLine($"Duplicate: {duplicate}");
        Console.WriteLine($"Same text: {original == duplicate}");
    }
}

How It Works

  1. Call the static method. string.Copy(original) takes the source string.
  2. Allocate a new string. Characters are copied into a fresh string object.
  3. Compare with ==. Content equality is true—same characters.
  4. Original unchanged. Strings are immutable; original still holds "Hello, C#".

Example 2 — Copy vs Assignment

Assignment reuses a reference; Copy() creates a new object. Text equality stays true either way.

C#
using System;

class Program {
    static void Main() {
        string a = "CodeToFun";

        string assigned = a;
        string copied = string.Copy(a);

        Console.WriteLine($"assigned == a? {assigned == a}");
        Console.WriteLine($"copied == a?   {copied == a}");
        Console.WriteLine($"same object (assign)? {object.ReferenceEquals(a, assigned)}");
        Console.WriteLine($"same object (copy)?   {object.ReferenceEquals(a, copied)}");
    }
}

How It Works

  1. Assign. assigned = a points at the same string object.
  2. Copy. string.Copy(a) builds another string with the same characters.
  3. == checks content. Both paths compare equal as text.
  4. ReferenceEquals checks identity. Assignment shares the object; Copy typically does not.

Example 3 — Null Throws

Copy(null) is invalid. Guard nulls before calling.

C#
using System;

class Program {
    static void Main() {
        string source = null;

        try {
            string.Copy(source);
        } catch (ArgumentNullException) {
            Console.WriteLine("Copy(null) throws ArgumentNullException");
        }

        source = "Safe";
        string ok = string.Copy(source);
        Console.WriteLine($"Copied: {ok}");
    }
}

How It Works

  1. Pass null. string.Copy(null) cannot allocate from a missing source.
  2. Catch the exception. Runtime throws ArgumentNullException.
  3. Validate first. Only call Copy when the source is a real string.
  4. Happy path. With "Safe", Copy returns a new string with the same text.

Frequently Asked Questions

Copy() creates another string instance with the same text.
str is required. It is the string to copy.
A new string instance with the same characters.
Usually no. Prefer a normal assignment. Copy is obsolete in modern .NET.
No. For part of a string, use Substring or related APIs.

Next: CopyTo()

Learn how to copy string characters into a char array.

CopyTo() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful