This post will discuss how to append a value to the end of a list in C#.

1. Using List<T>.Add() Method

The recommended approach to insert an object at the end of a list is using the List<T>.Add() method. The following example demonstrates how to insert an integer in a List<int>.

Download  Run Code

2. Using List<T>.Insert() Method

The List<T>.Insert() method inserts the specified element into the List<T> at the specified index. It can be used as follows to insert an element at the end of a list.

Download  Run Code

3. Using Enumerable.Append() Method

Starting with .NET Framework 4.7.1, you can use the Enumerable.Append() method to append a value to the end of a sequence. This method does not modify the items of the original sequence, but returns a new collection that ends with the specified element. The following code example demonstrates how to use Append() method to create a copy of a list with the new element.

Download  Run Code

That’s all about appending a value to the end of a list in C#.