Linq By Example

Append

Append can be used to add a value to the end of a collection. At first glance it may appear to be identical to List.Add(), however append does not modify the list in place and instead recreates a new list, with the item appended. Because of this, Append() can sometimes lead to unintended bugs if you are not assigning the list to a new variable.

Append vs Add

As noted above, Append does not modify a list in place and instead, the list is cloned, appended, and then returned. If you require modifying the list in place, Add should be used instead.
    
using System;
using System.Collections.Generic;
using System.Linq;

var appendList = new List();
appendList.Append(1);
Console.WriteLine(appendList.Count()); //Returns 0 because we did not assign the return value of append. 
appendList = appendList.Append(1).ToList();
Console.WriteLine(appendList.Count()); //Returns 1 because we reassigned after appending. 

var addList = new List();
addList.Add(1);
Console.WriteLine(addList.Count);//Returns 1 because Add modifies a list in place. 

  

Append Performance

The constant cloning of a collection to append a new value is relatively expensive compared to simply calling Add on a List. This should be kept in mind if Add is available. Again, Append's main use is that it does not modify a collection in place, but if you do not need this, then you are taking a performance hit for nothing.

Below is a performance benchmark that compares calling Append vs Add on a list. Append can take up to 30x longer to complete.
    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

IEnumerable appendList = new List();
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < 1000000; i++)
{
    appendList = appendList.Append(i);
}
watch.Stop();
Console.WriteLine($"Append Took : {watch.ElapsedMilliseconds}ms"); //Returns 0 because we did not assign the return value of append. 

var addList = new List();
watch.Reset();
watch.Start();
for (int i = 0; i < 1000000; i++)
{
    addList.Add(i);
}
watch.Stop();
Console.WriteLine($"Add Took : {watch.ElapsedMilliseconds}ms"); //Returns 0 because we did not assign the return value of append.