C# – Create List from Array

In C#, an array has a fixed length after it is created, while List<T> is a generic collection whose size can grow or shrink. When you already have values in an array and need list operations such as Add(), Remove(), or Insert(), you can create a new list from the array.

The most direct approach is to pass the array to the List<T> constructor. You can also use LINQ’s ToList() method, or AddRange() when you already have a list and want to append the array elements.

C# List constructor syntax for converting an array

For an array and a list with the same element type, pass the array to the list constructor:

</>
Copy
List<T> list = new List<T>(array);

For example, an int[] can be used to create a List<int>, and a string[] can be used to create a List<string>. The list is a separate collection, so adding or removing items from the list does not change the length of the original array.

Example 1 – Create C# List from Array

In this example, the numbers variable is an int[]. We pass it to the List<int> constructor to create nums with the same integer elements.

Program.cs

</>
Copy
using System;
using System.Collections.Generic;

class Program {
    static void Main(string[] args) {
        //array
        int[] numbers = {10, 20, 30, 40};
        //create list from array
        List<int> nums = new List<int>(numbers);
        
        //print list
        foreach (int num in nums) {
            Console.WriteLine(num);
        }
    }
}

Run the above C# program. Now the new list contains all the elements of the array.

Output

10
20
30
40

Example 2 – Create C# List from String Array

In this example, we create a List<string> from a string[]. The constructor reads the strings from the array and places them into the new list in the same order.

Program.cs

</>
Copy
using System;
using System.Collections.Generic;

class Program {
    static void Main(string[] args) {
        //array
        string[] numbers = {"One", "Two", "Three"};
        //create list from array
        List<string> nums = new List<string>(numbers);
        
        //print list
        foreach (string num in nums) {
            Console.WriteLine(num);
        }
    }
}

Run the above C# program.

Output

One
Two
Three

Convert a C# array to List with ToList()

If your code already uses LINQ, ToList() is a concise alternative. Add using System.Linq;, then call ToList() on the array.

</>
Copy
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main(string[] args) {
        string[] colors = {"Red", "Green", "Blue"};

        List<string> colorList = colors.ToList();

        foreach (string color in colorList) {
            Console.WriteLine(color);
        }
    }
}

The result is a new List<string> containing the array elements in the same order.

Add a C# array to an existing List with AddRange()

Use AddRange() when you already have a list and want to append every element from an array instead of creating the list directly from that array.

</>
Copy
using System;
using System.Collections.Generic;

class Program {
    static void Main(string[] args) {
        int[] numbers = {30, 40};
        List<int> nums = new List<int> {10, 20};

        nums.AddRange(numbers);

        foreach (int num in nums) {
            Console.WriteLine(num);
        }
    }
}
10
20
30
40

Array and List are separate collections after conversion

Creating a list from an array does not make the list a resizable view of that array. The list receives the array elements, but its collection structure is independent. Therefore, adding or removing list items does not add or remove array elements.

</>
Copy
int[] numbers = {10, 20, 30};
List<int> nums = new List<int>(numbers);

nums.Add(40);

Console.WriteLine(numbers.Length);
Console.WriteLine(nums.Count);
3
4

For value types such as int, the values are copied into the new list. For reference types, the array and list contain references to the same objects, even though the array and list themselves are separate collections.

Convert object arrays and other typed arrays to List<T>

The same constructor pattern works with other element types. For example, an object[] can create a List<object> directly:

</>
Copy
object[] values = {1, "Hello", true};
List<object> valueList = new List<object>(values);

If you need to change each element to a different type, that is a transformation rather than a simple array-to-list conversion. Convert or project the elements first, then create the list.

List<T> is different from the non-generic ArrayList class

List<T> and ArrayList are different collection types in C#. List<T> is generic and keeps a specific element type at compile time. ArrayList stores values as object. For new code, use List<T> when you want a typed resizable collection.

Choose between the List constructor, ToList(), and AddRange()

  • Use new List<T>(array) when you are creating a list directly from an existing array.
  • Use array.ToList() when LINQ is already appropriate in the surrounding code or when the array is part of a LINQ query.
  • Use AddRange(array) when the destination list already exists and you want to append all array elements.

C# array-to-List conversion summary

To create a List<T> from a C# array, pass the array to the List<T> constructor or call ToList(). If the destination list already exists, use AddRange(). In each case, the list can then grow or shrink independently of the source array.

In this C# Tutorial, we learned how to create a list from a given array.