Language

MemoryExtensions.AsSpan Method

Definition

Creates a new read-only span over a string.

Overloads

Name Description
AsSpan(String, Int32, Int32)

Creates a new read-only span over a portion of the target string from a specified position for a specified number of characters.

AsSpan(String, Range)

Creates a new ReadOnlySpan over a portion of a target string using the range start and end indexes.

AsSpan(String, Index)

Creates a new ReadOnlySpan over a portion of the target string from a specified position to the end of the string.

AsSpan(String)

Creates a new read-only span over a string.

AsSpan(String, Int32)

Creates a new read-only span over a portion of the target string from a specified position to the end of the string.

AsSpan(T[], Int32, Int32)

Creates a new span over the portion of the target array beginning at a specified position for a specified length.

AsSpan(ArraySegment)

Creates a new span over a target array segment.

AsSpan(T[])

Creates a new span over a target array.

AsSpan(ArraySegment, Index)

Creates a new span over a portion of the target array segment beginning at a specified index and ending at the end of the segment.

AsSpan(ArraySegment, Int32)

Creates a new span over a portion of a target array segment from a specified position to the end of the segment.

AsSpan(ArraySegment, Range)

Creates a new span over a portion of a target array segment using the range start and end indexes.

AsSpan(T[], Index)

Creates a new span over the portion of the target array defined by an Index value.

AsSpan(T[], Int32)

Creates a new span over a portion of the target array starting at a specified position to the end of the array.

AsSpan(T[], Range)

Creates a new span over a portion of a target array defined by a Range value.

AsSpan(ArraySegment, Int32, Int32)

Creates a new span over a portion of a target array segment from a specified position for a specified length.

AsSpan(String, Int32, Int32)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new read-only span over a portion of the target string from a specified position for a specified number of characters.

public:
[System::Runtime::CompilerServices::Extension]
 static ReadOnlySpan AsSpan(System::String ^ text, int start, int length);
public static ReadOnlySpan AsSpan(this string? text, int start, int length);
static member AsSpan : string * int * int -> ReadOnlySpan

Public Function AsSpan (text As String, start As Integer, length As Integer) As ReadOnlySpan(Of Char)

Parameters

text
String

The target string.

start
Int32

The index at which to begin this slice.

length
Int32

The desired length for the slice.

Returns

The read-only span representation of the string.

Exceptions

start, length, or start + length is not in the range of text.

Remarks

Returns default when text is null.

Applies to

AsSpan(String, Range)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new ReadOnlySpan over a portion of a target string using the range start and end indexes.

public:
[System::Runtime::CompilerServices::Extension]
 static ReadOnlySpan AsSpan(System::String ^ text, Range range);
public static ReadOnlySpan AsSpan(this string? text, Range range);
static member AsSpan : string * Range -> ReadOnlySpan

Public Function AsSpan (text As String, range As Range) As ReadOnlySpan(Of Char)

Parameters

text
String

The target string.

range
Range

The range that has start and end indexes to use for slicing the string.

Returns

The read-only span representation of the string.

Exceptions

text is null.

range's start or end index is not within the bounds of the string.

range's start index is greater than its end index.

Applies to

AsSpan(String, Index)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new ReadOnlySpan over a portion of the target string from a specified position to the end of the string.

public:
[System::Runtime::CompilerServices::Extension]
 static ReadOnlySpan AsSpan(System::String ^ text, Index startIndex);
public static ReadOnlySpan AsSpan(this string? text, Index startIndex);
static member AsSpan : string * Index -> ReadOnlySpan

Public Function AsSpan (text As String, startIndex As Index) As ReadOnlySpan(Of Char)

Parameters

text
String

The target string.

startIndex
Index

The index at which to begin this slice.

Returns

The read-only span representation of the string.

Exceptions

startIndex is less than 0 or greater than text.Length.

Applies to

AsSpan(String)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new read-only span over a string.

public:
[System::Runtime::CompilerServices::Extension]
 static ReadOnlySpan AsSpan(System::String ^ text);
public static ReadOnlySpan AsSpan(this string? text);
static member AsSpan : string -> ReadOnlySpan

Public Function AsSpan (text As String) As ReadOnlySpan(Of Char)

Parameters

text
String

The target string.

Returns

The read-only span representation of the string.

Remarks

Returns default when text is null.

Applies to

AsSpan(String, Int32)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new read-only span over a portion of the target string from a specified position to the end of the string.

public:
[System::Runtime::CompilerServices::Extension]
 static ReadOnlySpan AsSpan(System::String ^ text, int start);
public static ReadOnlySpan AsSpan(this string? text, int start);
static member AsSpan : string * int -> ReadOnlySpan

Public Function AsSpan (text As String, start As Integer) As ReadOnlySpan(Of Char)

Parameters

text
String

The target string.

start
Int32

The index at which to begin this slice.

Returns

The read-only span representation of the string.

Exceptions

start is less than 0 or greater than text.Length.

Thrown when text is null.

Applies to

AsSpan(T[], Int32, Int32)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new span over the portion of the target array beginning at a specified position for a specified length.

public:
generic 
[System::Runtime::CompilerServices::Extension]
 static Span AsSpan(cli::array  ^ array, int start, int length);
public static Span AsSpan(this T[]? array, int start, int length);
static member AsSpan : 'T[] * int * int -> Span<'T>

Public Function AsSpan(Of T) (array As T(), start As Integer, length As Integer) As Span(Of T)

Type Parameters

T

The type of the array.

Parameters

array
T[]

The target array.

start
Int32

The index at which to begin the span.

length
Int32

The number of items in the span.

Returns

The span representation of the array.

Exceptions

array is covariant, and the array's type is not exactly T[]".

start, length, or start + length is not in the range of array.

Remarks

Returns default when array is null.

Applies to

AsSpan(ArraySegment)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new span over a target array segment.

public:
generic 
[System::Runtime::CompilerServices::Extension]
 static Span AsSpan(ArraySegment segment);
public static Span AsSpan(this ArraySegment segment);
static member AsSpan : ArraySegment<'T> -> Span<'T>

Public Function AsSpan(Of T) (segment As ArraySegment(Of T)) As Span(Of T)

Type Parameters

T

The type of the array segment.

Parameters

segment
ArraySegment

The array segment to convert.

Returns

The span representation of the array segment.

Applies to

AsSpan(T[])

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new span over a target array.

public:
generic 
[System::Runtime::CompilerServices::Extension]
 static Span AsSpan(cli::array  ^ array);
public static Span AsSpan(this T[]? array);
static member AsSpan : 'T[] -> Span<'T>

Public Function AsSpan(Of T) (array As T()) As Span(Of T)

Type Parameters

T

The type of the array.

Parameters

array
T[]

The array to convert.

Returns

The span representation of the array.

Applies to

AsSpan(ArraySegment, Index)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new span over a portion of the target array segment beginning at a specified index and ending at the end of the segment.

public:
generic 
[System::Runtime::CompilerServices::Extension]
 static Span AsSpan(ArraySegment segment, Index startIndex);
public static Span AsSpan(this ArraySegment segment, Index startIndex);
static member AsSpan : ArraySegment<'T> * Index -> Span<'T>

Public Function AsSpan(Of T) (segment As ArraySegment(Of T), startIndex As Index) As Span(Of T)

Type Parameters

T

The type of the array segment.

Parameters

segment
ArraySegment

The target array segment.

startIndex
Index

The index at which to begin the Span.

Returns

The span representation of the array segment.

Applies to

AsSpan(ArraySegment, Int32)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new span over a portion of a target array segment from a specified position to the end of the segment.

public:
generic 
[System::Runtime::CompilerServices::Extension]
 static Span AsSpan(ArraySegment segment, int start);
public static Span AsSpan(this ArraySegment segment, int start);
static member AsSpan : ArraySegment<'T> * int -> Span<'T>

Public Function AsSpan(Of T) (segment As ArraySegment(Of T), start As Integer) As Span(Of T)

Type Parameters

T

The type of the array segment.

Parameters

segment
ArraySegment

The target array segment.

start
Int32

The index at which to begin the san.

Returns

The span representation of the array segment.

Exceptions

segment is covariant, and the array's type is not exactly T[].

start is less than 0 or greater than segment.Count.

Remarks

Returns default when segment is null.

Applies to

AsSpan(ArraySegment, Range)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new span over a portion of a target array segment using the range start and end indexes.

public:
generic 
[System::Runtime::CompilerServices::Extension]
 static Span AsSpan(ArraySegment segment, Range range);
public static Span AsSpan(this ArraySegment segment, Range range);
static member AsSpan : ArraySegment<'T> * Range -> Span<'T>

Public Function AsSpan(Of T) (segment As ArraySegment(Of T), range As Range) As Span(Of T)

Type Parameters

T

The type of the array segment.

Parameters

segment
ArraySegment

The target array segment.

range
Range

The range which has start and end indexes to use for slicing the array.

Returns

The span representation of the array segment.

Applies to

AsSpan(T[], Index)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new span over the portion of the target array defined by an Index value.

public:
generic 
[System::Runtime::CompilerServices::Extension]
 static Span AsSpan(cli::array  ^ array, Index startIndex);
public static Span AsSpan(this T[]? array, Index startIndex);
static member AsSpan : 'T[] * Index -> Span<'T>

Public Function AsSpan(Of T) (array As T(), startIndex As Index) As Span(Of T)

Type Parameters

T

The array type.

Parameters

array
T[]

The array to convert.

startIndex
Index

The starting index.

Returns

The span representation of the array.

Applies to

AsSpan(T[], Int32)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new span over a portion of the target array starting at a specified position to the end of the array.

public:
generic 
[System::Runtime::CompilerServices::Extension]
 static Span AsSpan(cli::array  ^ array, int start);
public static Span AsSpan(this T[]? array, int start);
static member AsSpan : 'T[] * int -> Span<'T>

Public Function AsSpan(Of T) (array As T(), start As Integer) As Span(Of T)

Type Parameters

T

The type of the array.

Parameters

array
T[]

The array to convert.

start
Int32

The initial index from which the array will be converted.

Returns

The span representation of the array.

Applies to

AsSpan(T[], Range)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new span over a portion of a target array defined by a Range value.

public:
generic 
[System::Runtime::CompilerServices::Extension]
 static Span AsSpan(cli::array  ^ array, Range range);
public static Span AsSpan(this T[]? array, Range range);
static member AsSpan : 'T[] * Range -> Span<'T>

Public Function AsSpan(Of T) (array As T(), range As Range) As Span(Of T)

Type Parameters

T

The type of the array.

Parameters

array
T[]

The array to convert.

range
Range

The range of the array to convert.

Returns

The span representation of the array.

Applies to

AsSpan(ArraySegment, Int32, Int32)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Creates a new span over a portion of a target array segment from a specified position for a specified length.

public:
generic 
[System::Runtime::CompilerServices::Extension]
 static Span AsSpan(ArraySegment segment, int start, int length);
public static Span AsSpan(this ArraySegment segment, int start, int length);
static member AsSpan : ArraySegment<'T> * int * int -> Span<'T>

Public Function AsSpan(Of T) (segment As ArraySegment(Of T), start As Integer, length As Integer) As Span(Of T)

Type Parameters

T

The type of the array segment.

Parameters

segment
ArraySegment

The target array segment.

start
Int32

The index at which to begin the span.

length
Int32

The number of items in the span.

Returns

The span representation of the array.

Exceptions

segment is covariant, and the array's type is not exactly T[].

start, length, or start + length is not in the range of segment.

Remarks

Returns default when segment is null.

Applies to