C# Array CopyTo() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

In C#, CopyTo is an instance method: you call it on the source array. It copies every element into another array starting at a destination index you choose.

It is a convenient form of “copy all of me into that array over there.” For partial ranges, use static Array.Copy instead.

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

Syntax

Call CopyTo on the source array. Pass the destination and the starting index.

C#
src.CopyTo(dest, 0);
src.CopyTo(dest, 2);
CallWhat it does
src.CopyTo(dest, 0)Copies all of src into dest starting at index 0.
src.CopyTo(dest, 2)Leaves dest[0] and dest[1] alone; places src from index 2 onward.

dest must have enough room: index + src.Length <= dest.Length.

Library declarations
C#
public void CopyTo(Array array, int index);
public void CopyTo(Array array, long index);

Parameters

ParameterDescription
arrayRequired. Destination array.
indexRequired. Starting index in the destination.

Return Value

Return ValueDescription
voidUpdates the destination in place.

C# Examples

Example 1 — Copy Into the Start

Place all source values at the beginning of a larger destination.

C#
using System;

class Program {
    static void Main() {
        int[] src = { 10, 20, 30 };
        int[] dest = new int[5];

        src.CopyTo(dest, 0);

        Console.WriteLine(string.Join(", ", dest));
    }
}

How It Works

  1. Instance call. The source is src; you do not pass it again.
  2. Index 0. Writing starts at the first destination slot.
  3. Full source. All three values are copied.
  4. Tail zeros. Unused destination slots keep their defaults.

Example 2 — Copy Starting at Index 2

Leave the first two destination slots unchanged.

C#
using System;

class Program {
    static void Main() {
        string[] src = { "X", "Y" };
        string[] dest = { "a", "b", "c", "d" };

        src.CopyTo(dest, 2);

        Console.WriteLine(string.Join(", ", dest));
    }
}

How It Works

  1. Offset. Destination index 2 is where "X" lands.
  2. Prefix kept. a and b were never overwritten.
  3. Two writes. Source length 2 replaces c and d.
  4. Bounds check. Index 2 + length 2 fits in dest length 4.

Example 3 — CopyTo Matches a Full Array.Copy

Show the same result as Array.Copy(src, dest, src.Length).

C#
using System;

class Program {
    static void Main() {
        int[] src = { 4, 5 };
        int[] a = new int[2];
        int[] b = new int[2];

        src.CopyTo(a, 0);
        Array.Copy(src, b, src.Length);

        Console.WriteLine(string.Join(",", a) == string.Join(",", b));
        Console.WriteLine(string.Join(",", a));
    }
}

How It Works

  1. Same content. Both techniques fill a same-sized destination.
  2. Style choice. CopyTo reads nicely when the source is the subject.
  3. Partial copies. Prefer static Copy when source indexes matter.
  4. Equality check. Joined strings match, so the copies agree.

Frequently Asked Questions

It copies every element of the current array into another array starting at the given destination index.
CopyTo is an instance method and always copies the whole source. Array.Copy can copy a slice with source and destination indexes.
CopyTo throws an exception. Ensure index + source.Length is within destination.Length.
No. Only the written range changes. Other destination slots keep their old values.
The destination is treated as a flat Array. Prefer matching ranks and types for clarity.

Next: CreateInstance()

Create a new array at runtime by element type and lengths with System.Array.

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

14 people found this page helpful