Is there a difference between the .Append()
and the .Add()
method for lists in C#? I tried searching in Google and in the site but to my surprise n
List
in C# only has the void Add(T item) method to modify the instance add a single item to the list.
IEnumerableIEnumerable
interface (which is implemented by all lists). It does not modify the original list instance, but returns a new enumerable which will yield the specified element at the end of the sequence.
They cannot be used interchangably and behave differently with different outcomes and different side effects. Asking about their relative performance does not make sense as such.
var list = new List();
list.Add("one");
list.Add("two");
// list contains: [ one, two ]
list.Append("three");
// list still contains: [ one, two ]