Skip to content

Remove Span(T[], int) ctor #23294

@stephentoub

Description

@stephentoub

Span currently has these ctors with two parameters:

  • public Span(T[], int)
  • public Span(void*, int)
  • internal Span(ref T, int) (currently internal, but potentially public in the future)

The usability issue is that the int parameter doesn't always mean the same thing: for the void* and ref ctors, it means length, but for the T[] ctor, it means offset. This leads to subtle bugs when switching back and forth between inputs, as a length can accidentally become an offset, or vice versa.

We should remove the public Span(T[], int) ctor to avoid the confusion. We will still have the public Span(T[]) ctor for cases where you want a span over the whole array, and we will still have the public Span(T[], int, int) ctor for cases where you want to specify the array, an offset, and a length, and for cases where you only want to specify the array and an offset, you can use new Span<T>(arr).Slice(offset) without ambiguity.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions