C# Array Clone() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

In C#, Clone() creates a new array of the same length and copies each element into it. For value types such as int, the numbers are duplicated. For reference types such as string or custom classes, only the references are copied (a shallow copy).

The method returns object, so cast back to the array type. Array.Copy is another way to copy into an existing target array.

This is an instance member of System.Array. You call it on an array variable with a dot, such as arr.Clone(...). Arrays in C# have a fixed length after creation; use List<T> when the count must grow.

Syntax

Call Clone on the array instance, then cast the result.

C#
int[] copy = (int[])nums.Clone();
object boxed = names.Clone();
CallWhat it does
(int[])nums.Clone()New int array with the same values as nums.
(string[])names.Clone()New string array sharing the same string references.

Shallow copy means nested objects are not deep-cloned. Changing a mutable object through either array affects both.

Library declarations
C#
public object Clone();

Parameters

ParameterDescription
NoneClone() takes no parameters.

Return Value

Return ValueDescription
objectA new array with the same Length and Rank. Cast to the concrete array type before indexing.

C# Examples

Example 1 — Clone an Int Array

Change the copy and prove the original stays intact.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 1, 2, 3 };
        int[] copy = (int[])nums.Clone();

        copy[0] = 99;

        Console.WriteLine("nums: " + string.Join(", ", nums));
        Console.WriteLine("copy: " + string.Join(", ", copy));
    }
}

How It Works

  1. New array object. Clone allocates a separate int array.
  2. Values copied. At first both hold 1, 2, 3.
  3. Independent ints. Writing copy[0] = 99 does not change nums.
  4. Cast required. Without (int[]), the compiler only sees object.

Example 2 — Shallow Copy with Reference Types

Both arrays share the same mutable object reference.

C#
using System;

class Box {
    public int Value;
}

class Program {
    static void Main() {
        Box[] a = { new Box { Value = 5 } };
        Box[] b = (Box[])a.Clone();

        b[0].Value = 42;

        Console.WriteLine("a[0].Value = " + a[0].Value);
        Console.WriteLine("b[0].Value = " + b[0].Value);
        Console.WriteLine("Same object? " + object.ReferenceEquals(a[0], b[0]));
    }
}

How It Works

  1. Array shells differ. a and b are different arrays.
  2. Element shared. Index 0 in both points at one Box.
  3. Mutation shows. Changing Value through b is visible on a.
  4. Deep copy needs more. Clone each element yourself if you need independent objects.

Example 3 — Clone Keeps Length and Rank

Print metadata to confirm the copy matches the source shape.

C#
using System;

class Program {
    static void Main() {
        string[] names = { "Ann", "Bob" };
        string[] copy = (string[])names.Clone();

        Console.WriteLine("Length: " + copy.Length);
        Console.WriteLine("Rank: " + copy.Rank);
        Console.WriteLine("Same array object? " + object.ReferenceEquals(names, copy));
    }
}

How It Works

  1. Shape preserved. Length and Rank match the source.
  2. New identity. ReferenceEquals is false—the arrays are different objects.
  3. Strings are immutable. Sharing string references is usually safe.
  4. Alternative. Array.Copy can fill an existing destination array instead.

Frequently Asked Questions

It returns a new array with the same size and a shallow copy of the elements. The return type is object.
No. Reference-type elements still point at the same objects. Only the array shell is new.
Clone creates a new array and returns it as object. Copy writes into a destination array you already have.
Yes. Cast to int[], string[], or the correct array type before you index it.
Yes. Rank and lengths are preserved in the new array.

Next: ConstrainedCopy()

Copy a range and roll back the destination if the copy fails with System.Array.

ConstrainedCopy() 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.

10 people found this page helpful