C#
Generics
List<T>
add method
collections

Adding List<T>.Add another list

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In C#, List<T>.Add inserts exactly one element of type T. If you want to append every element from another list, the method you usually want is AddRange, not Add.

What Add Actually Does

If the list type is List<int>, then Add expects one int.

csharp
1using System;
2using System.Collections.Generic;
3
4class Program
5{
6    static void Main()
7    {
8        var numbers = new List<int> { 1, 2 };
9        numbers.Add(3);
10        Console.WriteLine(string.Join(", ", numbers));
11    }
12}

That is ordinary single-item insertion. It changes the list length by one.

Use AddRange to Append Another List

If you want all items from another collection appended to the first list, use AddRange.

csharp
1using System;
2using System.Collections.Generic;
3
4class Program
5{
6    static void Main()
7    {
8        var first = new List<int> { 1, 2 };
9        var second = new List<int> { 3, 4, 5 };
10
11        first.AddRange(second);
12
13        Console.WriteLine(string.Join(", ", first));
14    }
15}

This is the standard in-place way to combine two lists of the same element type.

Why Add(secondList) Fails

This code does not compile for List<int>:

csharp
var first = new List<int> { 1, 2 };
var second = new List<int> { 3, 4 };
first.Add(second);

It fails because first is a List<int>, so Add requires one int, not a List<int>.

The only time Add(secondList) makes sense is when the element type is itself a list, such as List<List<int>>. That is a different structure entirely.

Create a New Combined List Instead of Mutating

If you do not want to modify the original list, copy it first and then append the second list.

csharp
1using System;
2using System.Collections.Generic;
3
4class Program
5{
6    static void Main()
7    {
8        var first = new List<int> { 1, 2 };
9        var second = new List<int> { 3, 4 };
10
11        var combined = new List<int>(first);
12        combined.AddRange(second);
13
14        Console.WriteLine(string.Join(", ", combined));
15    }
16}

This is often the cleanest solution when the original inputs should stay unchanged.

Concat Is a Non-Mutating Alternative

LINQ also offers Concat.

csharp
1using System;
2using System.Collections.Generic;
3using System.Linq;
4
5class Program
6{
7    static void Main()
8    {
9        var first = new List<int> { 1, 2 };
10        var second = new List<int> { 3, 4 };
11
12        var combined = first.Concat(second).ToList();
13        Console.WriteLine(string.Join(", ", combined));
14    }
15}

Concat is useful when you are already composing other LINQ operations. AddRange is often clearer when the intent is simply to append one collection to another in place.

Which One Should You Choose?

Use AddRange when:

  • you want to mutate the original list,
  • you want the most direct list-to-list append operation,
  • you are not already in a LINQ pipeline.

Use Concat when:

  • you want a non-mutating result,
  • you are already composing sequence operations,
  • a deferred-sequence style reads more naturally in context.

The important part is to distinguish "append one item" from "append many items."

Common Pitfalls

A common mistake is trying Add(otherList) when the list element type is not itself a list. That is simply the wrong method for the job.

Another issue is mutating a list with AddRange when you actually intended to keep the original untouched.

Developers also sometimes forget ToList() after Concat and then wonder why the result is not a concrete List<T> yet.

Summary

  • 'Add inserts one element of type T.'
  • 'AddRange appends all elements from another collection.'
  • Use AddRange for in-place list-to-list appending.
  • Copy the first list before appending if you need to preserve the original.
  • Use Concat when you want a non-mutating LINQ-style combination.

Course illustration
Course illustration

All Rights Reserved.