C# List Declaration: Syntax and Initialization
Learn how to declare and initialize List<T> in C#, including empty lists, collection initializers, initial capacity, var inference, and common declaration mistakes.

Declaring a List<T> in C# means creating an instance of the generic collection type. The most direct form is new List<T>(), where T is the element type:
List<int> numbers = new List<int>();This creates an empty list. You can also populate the list at declaration time with a collection initializer, or pass an initial capacity when you know the list will be large. The sections below cover those forms and the tradeoffs between them.
Core Declaration Syntax
Use an explicit type when the list type is the important information:
List<string> names = new List<string>();Use var when the right-hand side already makes the type obvious:
var names = new List<string>();Both declarations create the same List<string> object. var is compile-time type inference, not a dynamically typed value, so it does not reduce type safety. For complex generic types, some readers still prefer an explicit type:
Dictionary<string, List<int>> lookup = new Dictionary<string, List<int>>();Initializing with Known Values
A collection initializer lets you declare and populate a list in one expression:
List<int> scores = new List<int> { 90, 85, 88 };This is equivalent to creating the list and calling Add for each value. It does not change runtime behavior, but it keeps starting data together with the declaration.
For a custom type, combine the collection initializer with object initializers:
var employees = new List<Employee>
{
new Employee { Id = 1, Name = "Alice" },
new Employee { Id = 2, Name = "Bob" }
};Setting Initial Capacity
Capacity is the size of the internal array that backs the list. The List<T> constructor accepts an initial capacity:
var customers = new List<Customer>(100);This reserves space for about 100 customer references. It does not restrict the list to 100 items. If the expected size is known and large, supplying it avoids repeated array resizes as the list grows.
The default constructor creates a list with zero initial capacity. The list grows as you add elements, and the exact growth policy is an implementation detail. Passing a capacity close to the final size reduces avoidable allocations and copies.
Using var for Type Inference
var is a shorter way to declare the same type, not a different type:
var items = new List<Order>();The compiler determines the type from the right-hand side. Use it when the type is clear to someone reading the code.
You can also use var when building a list from a query:
var evenNumbers = Enumerable.Range(1, 100).Where(n => n % 2 == 0).ToList();ToList() executes the query and creates a List<int>.
A common invalid pattern is using var with an array-like literal but no collection type:
var numbers = { 1, 2, 3 }; // Invalid C#You must provide a collection type: new List<int> { 1, 2, 3 } creates a list, while new[] { 1, 2, 3 } creates an array.
Common Declaration Mistakes
A local list variable must be assigned before it is used:
List<int> numbers;
numbers.Add(1); // Compiler error CS0165: use of unassigned local variableIf the declaration is a class field and no instance is assigned, the field defaults to null, and calling Add throws NullReferenceException at runtime. Initialize at declaration or in a constructor.
Another common mistake is declaring an array when you need a resizable list. Arrays use int[] or new int[] { ... }, have a fixed length, and cannot grow. List<T> is resizable and is generally the right choice when the number of elements changes.
A design-level mistake is exposing a mutable List<T> when callers only need to read it. Returning IReadOnlyList<T> from a property is usually better:
private List<Order> _orders = new List<Order>();
public IReadOnlyList<Order> Orders => _orders;The internal list stays mutable, but callers cannot modify it through the property.
Choosing Between List and Other Collections
List<T> is the standard resizable collection when you need index access and ordered enumeration. Use it unless another collection maps more directly to the operation:
| Collection | Strengths | Weaknesses | Best Use Case |
|---|---|---|---|
List<T> | Index access, fast enumeration, dynamic size | Insertions/removals in the middle are O(n) | General-purpose resizable collection |
LinkedList<T> | O(1) insertions/removals at ends | No index access, higher memory overhead | Frequent insert/delete at ends |
HashSet<T> | O(1) lookups, uniqueness | Unordered, no index access | Set operations, deduplication |
Dictionary<TKey,TValue> | O(1) lookups by key | Requires unique keys, no order | Key-value mapping |
For a fixed-size collection, an array is usually more memory-efficient than List<T> and gives slightly faster element access, but its length cannot change.
Performance Considerations
List<T> stores elements in an internal array. When capacity is exceeded, it allocates a new array and copies existing elements, which is an O(n) operation. Setting the initial capacity near the expected final size reduces those resizes:
var lines = new List<string>(lineCount);This can reduce allocations when reading a file or materializing a known number of results. Reserving far more capacity than needed wastes memory, so choose capacity based on a realistic estimate.
Arrays avoid the small overhead of the List<T> wrapper and have slightly better cache locality, but the difference usually matters only in measurable hot paths. Profile before optimizing collection allocation patterns.
Thread Safety and Concurrency
A List<T> instance is not thread-safe for concurrent reads and writes. If multiple threads can mutate the same list, synchronize access. A simple lock-based implementation looks like:
private readonly object _lock = new object();
private List<int> _items = new List<int>();
public void AddItem(int item)
{
lock (_lock)
{
_items.Add(item);
}
}If other threads may modify the list while you iterate, copy it under the same lock before enumerating. For highly concurrent producer/consumer scenarios, ConcurrentQueue<T> or ConcurrentBag<T> from System.Collections.Concurrent may be more appropriate, depending on the access pattern.
Compatibility and Language Versions
Collection initializers and var have both been available since C# 3.0. List<T> is part of System.Collections.Generic, and most C# files need a using System.Collections.Generic; directive unless the project enables implicit global usings. The declaration syntax is the same across .NET Framework and modern .NET; differences are mostly in runtime behavior, not in how you declare a list.
Try matching browser tools
All toolsSmall utilities that fit C# work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related C# guides
All C# guidesC# Dispose vs Destructor: Key Differences Explained
c# dispose vs destructor: Understand the difference between Dispose and destructors in C#, when each runs, and how to manage unmanaged resources correctly.
C# Variable Declaration: Syntax and Practical Usage
Learn how to declare variables in C# with explicit types, var, and nullable annotations, and understand how defaults, scope, and readability affect your choices.
C# Primary Constructors for Classes: Syntax and Usage
Learn how to use C# primary constructors for classes: syntax, initialization, dependency injection, and limitations with practical examples.
C# IComparer: Custom Sorting with IComparer<T>
Learn how to implement IComparer<T> in C# to define custom sort order for arrays and lists, handle nulls, and avoid common performance pitfalls.
More in C#
All C# guidesThe guides filed next to this one in C#, in library order.