-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Collections
Milestone
Description
EDITED 9/22/2022 by @stephentoub:
namespace System.Collections.Generic
{
public class List<T>
{
+ public void AddSpan(ReadOnlySpan<T> span);
+ public void InsertSpan(int index, ReadOnlySpan<T> span);
+ public void CopyTo(Span<T> span);
}
}- We can't just add an AddRange overload as it's ambiguous for anything convertible to both span and enumerable, like array. We could alternatively call it AddRange and add overloads as well for arrays and strings.
Perhaps an AddRange overload taking a Span<T> can be added to the List class?
var list = new List<byte>();
list.AddRange(new Span<byte>());
Workarounds
foreach(var b in span)
list.Add(b); // Inefficient only copying one byte at a time
var list = new List<byte>();
var span = new Span<byte>();
list.AddRange(span.ToArray()); Silly allocation
airbreather, Raymonf, ixtreon, omghb, GSPP and 2 more
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Collections