C# List ToArray() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
List

Definition

In C#, List.ToArray() makes a new array and copies every item of the list into it, in the same order. The array length equals Count.

The array is separate from the list. Adding to the list afterwards does not change the array, and changing the array does not change the list. Use it when an API wants an array (T[]), or when you want a fixed snapshot of the list. If you already have an array and want to fill it, use CopyTo().

This is an instance member of List<T> (System.Collections.Generic). Call it on a list variable, such as numbers.ToArray(...). A List<T> is a class, so two variables can share one list. It keeps items in the order you put them, allows duplicates, and grows when needed. An array, by comparison, has a fixed length.

Syntax

Call it with no arguments. Store the result in a variable of type T[].

C#
List<int> numbers = new List<int> { 1, 2, 3 };
int[] array = numbers.ToArray();    // new int[3] { 1, 2, 3 }
CallWhat it does
numbers.ToArray()A new array with all items. Length equals Count.
new List<int>(array)The reverse trip: build a list from an array.
names.ToArray().LengthWorks, but it copies everything. Use names.Count instead when you only need the size.

ToArray is O(n) and allocates a new array every time. An empty list gives an empty array, never null. Like other copy methods, the copy is shallow: for classes, the array holds the same objects as the list. LINQ also has a ToArray() for any sequence, but List<T> has its own, which is faster.

Library declarations
C#
public T[] ToArray();

Parameters

ParameterDescription
NoneToArray() takes no parameters.

Return Value

Return ValueDescription
T[]A new array with a copy of every item, in order. Its Length equals the list's Count. Empty if the list is empty.

C# Examples

Example 1 — Turn a List into an Array

Convert a list, then show that the array and the list are independent.

C#
using System;
using System.Collections.Generic;

class Program {
    static void Main() {
        List<int> numbers = new List<int> { 1, 2, 3 };

        int[] array = numbers.ToArray();
        array[0] = 100;
        numbers.Add(4);

        Console.WriteLine(array.Length);
        Console.WriteLine(string.Join(", ", array));
        Console.WriteLine(string.Join(", ", numbers));
    }
}

How It Works

  1. Length is fixed. The array has 3 slots because the list had 3 items when ToArray was called.
  2. Edit the array. Setting array[0] = 100 changes only the array. The list still has 1 in its first slot.
  3. Grow the list. Adding 4 to the list makes it four items long, but the array cannot grow, and it stays at 3.
  4. Two independent objects. After the call, nothing links the array and the list.

Example 2 — Use Array Helpers on a List

Convert the list to an array to use Array.Reverse and Array.IndexOf, while the list stays as it was.

C#
using System;
using System.Collections.Generic;

class Program {
    static void Main() {
        List<string> names = new List<string> { "Asha", "Ben", "Chen" };

        string[] copy = names.ToArray();
        Array.Reverse(copy);

        Console.WriteLine(string.Join(", ", copy));
        Console.WriteLine(string.Join(", ", names));
        Console.WriteLine(Array.IndexOf(copy, "Ben"));
    }
}

How It Works

  1. Static helpers need arrays. Array.Reverse and Array.IndexOf take an array argument, so the list is converted first.
  2. Reverse the copy. The array is flipped to Chen, Ben, Asha.
  3. List unchanged. The second line shows the list still has its original order. Only the copy was reversed.
  4. Search the copy. In the reversed array, "Ben" is at index 1. In the list it is also at index 1, because it is the middle item.

Example 3 — Loop over a Snapshot While Removing

Loop over a copy of the list so you can remove items from the real list without breaking the loop.

C#
using System;
using System.Collections.Generic;

class Program {
    static void Main() {
        List<string> files = new List<string> { "a.txt", "b.tmp", "c.txt", "d.tmp" };

        foreach (string f in files.ToArray()) {
            if (f.EndsWith(".tmp")) {
                files.Remove(f);
            }
        }

        Console.WriteLine(string.Join(", ", files));
        Console.WriteLine(new List<int>().ToArray().Length);
    }
}

How It Works

  1. Loop over the copy. files.ToArray() builds an array first. The foreach walks that array, not the list.
  2. Remove from the real list. files.Remove(f) changes the list, which is safe here because the loop is not enumerating it.
  3. Without ToArray. Removing inside a foreach over files itself would throw InvalidOperationException on the next step.
  4. Empty gives empty. The last line shows an empty list converts to an array with length 0, never null.

Frequently Asked Questions

It creates a new array and copies all list items into it, in order. The array length equals the list Count.
No. It is a copy. Changing the array does not change the list, and changing the list does not change the array.
An empty array with Length 0. It never returns null.
Pass the array to the constructor: new List<int>(array), or call list.AddRange(array).
ToArray creates a new array for you. CopyTo copies into an array that you already created, at a position you choose.

Next: TrimExcess()

Give back unused room so Capacity moves close to Count (does nothing if the List is nearly full).

TrimExcess() 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