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.

Offen
#11,610 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area-System.Linq untriaged
Vorherrschende Sprache
C#
Sterne
949
Forks
1.7k
Ø Merge
2 T. 19 Std.
Gemergte PRs (30 T.)
52

Beschreibung

### 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Öffne xml/System.Linq/Enumerable.xml und suche die Anmerkungen zu Enumerable.Append und Enumerable.Prepend. Vergleiche die Formulierung mit dem im Issue gezeigten Verhalten des Lazy-Wrappers und aktualisiere anschließend beide Anmerkungen so, dass sie nicht implizieren, dass sofort eine Kopie der Collection erstellt wird; bestätige, dass die generierte API-Dokumentation das Ergebnis korrekt beschreibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
documentation
Issue-Typ
Dokumentation
Schwierigkeit
1/5
Geschätzter Aufwand
Unter einer Stunde
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.