dotnet / dotnet/dotnet-api-docs
Enumerable.Prepend and Enumerable.Append's remark "it creates a copy of the collection with the new element." can be misleading.
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
### Type of issue
Missing information
### Description
The remarks for both [Enumerable.Append](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.append?view=net-9.0#remarks) and [Enumerable.Prepend](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.prepend?view=net-9.0#remarks) can be misleading.
It currently states for both:
> 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 { "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 { "b", "c" };
var result = list.Prepend("a");
list.Add("d");
foreach (var item in result)
Console.WriteLine(item);
// Output:
// a
// b
// c
// d
```
### Page URL
https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.prepend?view=net-8.0#remarks
### Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Linq/Enumerable.xml
### Document Version Independent Id
9556f661-a131-5b65-913f-50770cc980cf
### Platform Id
acda5d20-c39a-4d6d-e70e-28d92c16a6b3
### Article author
@dotnet-bot
Contributor guide
Assessment
This issue has not been assessed yet.