ReadOnlySpan<T>.Slice Method

Definition

Overloads

Slice(Int32)

Forms a slice out of the current read-only span that begins at a specified index.

Slice(Int32, Int32)

Forms a slice out of the current read-only span starting at a specified index for a specified length.

Slice(Int32)

Source:
ReadOnlySpan.cs
Source:
ReadOnlySpan.cs
Source:
ReadOnlySpan.cs

Forms a slice out of the current read-only span that begins at a specified index.

C#
public ReadOnlySpan<T> Slice(int start);

Parameters

start
Int32

The zero-based index at which to begin the slice.

Returns

A span that consists of all elements of the current span from start to the end of the span.

Exceptions

start is greater than the number of items in the read-only span.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1

Slice(Int32, Int32)

Source:
ReadOnlySpan.cs
Source:
ReadOnlySpan.cs
Source:
ReadOnlySpan.cs

Forms a slice out of the current read-only span starting at a specified index for a specified length.

C#
public ReadOnlySpan<T> Slice(int start, int length);

Parameters

start
Int32

The zero-based index at which to begin this slice.

length
Int32

The desired length for the slice.

Returns

A read-only span that consists of length elements from the current span starting at start.

Exceptions

start is less than zero or greater than Length.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1