C# String Copy() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
String Methods

What You’ll Learn

The static method string.Copy() creates a new string object with the same characters as an existing string. It copies the entire string—not a portion. For everyday C# code, simple assignment often suffices because strings are immutable, but Copy() is useful when you explicitly need a separate instance.

01

Static Method

string.Copy(source)

02

New Instance

Separate object.

03

Full String

Not a substring.

04

vs Assignment

When each fits.

05

vs Clone()

New vs same ref.

06

Null Throws

ArgumentNullException.

Definition and Usage

In C#, string.Copy() duplicates the full character sequence of a string into a newly allocated string object. It is declared as a static method: string.Copy(original).

Because C# strings are immutable, you cannot modify characters in place anyway—so many programs never call Copy() and simply write string copy = original. Use Copy() when you deliberately want a new object reference with identical text, or when mirroring API patterns from other .NET types.

💡
Beginner Tip

Copy() is not the same as Substring(). Substring(3, 10) extracts part of a string; Copy(text) duplicates the whole string. If you only need a piece, use Substring() or range syntax text[3..13].

📝 Syntax

The single overload on System.String:

C#
public static string Copy(string str);

Parameters

  • str — the source string whose characters are copied. Must not be null.

Return Value

A new string containing the same characters as str. The original string is unchanged.

⚡ Quick Reference

GoalCode
Duplicate full stringstring.Copy(source)
Share same text (usual case)string copy = source
Extract a portionsource.Substring(3, 5)
Same instance (ICloneable)(string)source.Clone()
Copy chars to arraysource.CopyTo(0, buffer, 0, len)
Copy full
string.Copy(text)

New instance

Assign
string b = a

Most common

Substring
text.Substring(0, 5)

Partial text

CopyTo
text.CopyTo(...)

Into char[]

Examples Gallery

Run with dotnet run. Each example shows how Copy() works and how it differs from assignment, Clone(), and Substring().

📚 Getting Started

Duplicate a string with the static Copy() method.

Example 1 — Basic Copy() Usage

Create a duplicate of a greeting string and print both values.

C#
using System;

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

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

How It Works

string.Copy reads every character from original and stores them in a new string object. Both variables show the same text, but they may refer to different objects in memory.

Example 2 — Copy() Creates a New Object

Use ReferenceEquals to see that Copy() can produce a different instance than the source.

C#
using System;

class Program {
    static void Main() {
        string original = new string(new char[] { 'H', 'i' });
        string copied   = string.Copy(original);

        Console.WriteLine($"ReferenceEquals: {ReferenceEquals(original, copied)}");
        Console.WriteLine($"Content equal:   {original == copied}");
    }
}

How It Works

ReferenceEquals is false because Copy() allocated a new object. == compares character content and returns true. String interning may make literal comparisons share references, but Copy() from a freshly constructed string always creates a separate instance.

📈 Practical Patterns

Comparisons and choosing the right method.

Example 3 — Copy() vs Assignment

For immutable strings, assignment is usually the simpler choice.

C#
using System;

class Program {
    static void Main() {
        string message = "Welcome to C#";

        string viaAssign = message;
        string viaCopy   = string.Copy(message);

        Console.WriteLine($"Assign — same ref: {ReferenceEquals(message, viaAssign)}");
        Console.WriteLine($"Copy   — same ref: {ReferenceEquals(message, viaCopy)}");
        Console.WriteLine($"Both readable: {viaAssign} | {viaCopy}");
    }
}

How It Works

Assignment copies the reference, not the characters. Because strings cannot be mutated, that is safe for most code. Copy() forces a new object—useful only when you specifically need that separation.

Example 4 — Copy() vs Substring()

Copy() duplicates everything; Substring() extracts a slice.

C#
using System;

class Program {
    static void Main() {
        string text = "C# Programming";

        string fullCopy = string.Copy(text);
        string partial  = text.Substring(3, 11);  // "Programming"

        Console.WriteLine($"Copy:      '{fullCopy}'");
        Console.WriteLine($"Substring: '{partial}'");
    }
}

How It Works

Copy(text) has no startIndex or length parameters. To grab characters from index 3 for 11 characters, use Substring(3, 11) or modern range syntax text[3..14].

Example 5 — Copy() vs Clone()

Clone() returns the same instance for strings; Copy() allocates anew.

C#
using System;

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

        object clonedObj = original.Clone();
        string copied    = string.Copy(original);

        Console.WriteLine($"Clone same ref: {ReferenceEquals(original, clonedObj)}");
        Console.WriteLine($"Copy same ref:  {ReferenceEquals(original, copied)}");
        Console.WriteLine($"Clone text: {(string)clonedObj}");
        Console.WriteLine($"Copy text:  {copied}");
    }
}

How It Works

Clone() implements ICloneable and, for immutable strings, returns this. Copy() is the explicit way to get a new string object with identical characters. See the Clone() tutorial for more detail.

🚀 Common Use Cases

  • Explicit duplication — when API design or tests require a distinct string instance.
  • Legacy .NET code — older libraries may call String.Copy by convention.
  • Defensive copies — rare for strings (immutable), but mirrors patterns used with mutable types.
  • Learning object references — comparing Copy() with assignment in tutorials.
  • Contrasting with CopyTo()Copy() returns a string; CopyTo() writes into a char[].

🧠 How Copy() Works

1

You pass a source string

Example: string.Copy(source). Null throws immediately.

Input
2

Runtime reads all characters

The full length of str is measured—no partial range.

Measure
3

New string is allocated

Characters are copied into a fresh immutable string object.

Allocate
=

Duplicate string returned

Same text, new reference. Original str is unchanged.

📝 Notes

  • Copy() duplicates the entire string—not a range. Use Substring() for portions.
  • Passing null throws ArgumentNullException.
  • For most apps, string b = a is sufficient because strings are immutable.
  • Clone() on strings returns the same instance; Copy() creates a new one.
  • Do not confuse Copy() with CopyTo(), which copies characters into a character array.
  • String interning may cause literal assignments to share references—Copy() from a non-interned string avoids that sharing.

⚡ Optimization

Copy() allocates memory proportional to string length. Avoid calling it unnecessarily when assignment gives the same practical result. In tight loops over large collections, prefer passing strings by reference rather than copying each one with Copy(). For partial text, Substring() or spans may be more appropriate than copying the whole string first.

Conclusion

The C# Copy() method creates a new string object with the same characters as the source. It is straightforward, rarely needed in everyday code, but important to distinguish from Substring(), Clone(), and CopyTo().

Practice the examples above, then continue to CopyTo() to learn how to copy string characters into a character array.

💡 Best Practices

✅ Do

  • Use assignment for normal string duplication
  • Use Substring() when you need part of a string
  • Null-check before calling Copy()
  • Use CopyTo() when writing into a char[]
  • Compare with Clone() to understand references

❌ Don’t

  • Confuse Copy() with Substring()
  • Pass null to Copy()
  • Call Copy() in every loop without reason
  • Expect Copy() to modify the original string
  • Use Copy() when Clone() semantics are what you need

Key Takeaways

Knowledge Unlocked

Five things to remember about Copy()

Use these points whenever you duplicate strings in C#.

5
Core concepts
🔄 02

New Instance

Separate object.

Return
📝 03

Full String

Not Substring().

Scope
🔗 04

vs Assignment

Usually enough.

Daily use
⚠️ 05

null Throws

Check first.

Safety

❓ Frequently Asked Questions

Copy() is a static method that creates a new string containing the same characters as the input string. Call it as string.Copy(source). It does not extract a portion—that is Substring(). Copy() duplicates the entire string into a new instance.
string.Copy(str) where str is the source string. Example: string duplicate = string.Copy("Hello"); There is only one overload—it takes a single string argument.
It returns a new string object with the same character sequence as the argument. The original string is never modified because C# strings are immutable.
For everyday use, string b = a is usually enough because strings are immutable—you cannot change a in place. Copy() explicitly allocates a new string object. Use Copy() when you need a separate instance; use assignment when you only need to refer to the same text.
Copy() duplicates the entire string into a new instance. Substring(startIndex) or Substring(startIndex, length) extracts part of a string. Copy() has no startIndex or length parameters.
string.Copy(null) throws ArgumentNullException. Always validate with string.IsNullOrEmpty() or a null check before calling Copy() on user-provided input.
Did you know?

The .NET runtime interns string literals—identical literal text in your source code may share one object in memory. That is why ReferenceEquals("Hi", "Hi") can be true, while ReferenceEquals(string.Copy("Hi"), "Hi") is typically false. Content comparison with == still works either way.

Keep Building C# String Skills

Understand string duplication with Copy(), then continue to CopyTo() for copying into character arrays.

Next: CopyTo() →

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.

6 people found this page helpful