You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This method does not modify the elements of the collection. Instead, it creates a copy of the collection with the new element.
However it returns a lazily evaluated wrapper:
var original = new List<string> { "b", "c" };
var result = original.Prepend("a");
Console.WriteLine(result.GetType()); // System.Linq.Enumerable+PrependIterator`1
and no copy is actually made:
var list = new List<string> { "b", "c" };
var result = list.Prepend("a");
list.Add("d");
foreach (var item in result)
Console.WriteLine(item);
// Output:
// a
// b
// c
// d