อ่านในภาษาอังกฤษ แก้ไข

แชร์ผ่าน


MemoryExtensions.AsSpan Method

Definition

Overloads

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<T> over a portion of a target string using the range start and end indexes.

AsSpan(String, Index)

Creates a new ReadOnlySpan<T> 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>(T[], Int32, Int32)

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

AsSpan<T>(ArraySegment<T>)

Creates a new span over a target array segment.

AsSpan<T>(T[])

Creates a new span over a target array.

AsSpan<T>(ArraySegment<T>, 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<T>(ArraySegment<T>, Int32)

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

AsSpan<T>(ArraySegment<T>, Range)

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

AsSpan<T>(T[], Index)

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

AsSpan<T>(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>(T[], Range)

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

AsSpan<T>(ArraySegment<T>, 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

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

C#
public static ReadOnlySpan<char> AsSpan(this string? text, int start, int length);
C#
public static ReadOnlySpan<char> AsSpan(this string text, int start, int length);

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

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1

AsSpan(String, Range)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

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

C#
public static ReadOnlySpan<char> AsSpan(this string? text, Range range);

Parameters

text
String

The target string.

range
Range

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

Returns

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

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET 8, 9, 10

AsSpan(String, Index)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

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

C#
public static ReadOnlySpan<char> AsSpan(this string? text, Index startIndex);

Parameters

text
String

The target string.

startIndex
Index

The index at which to begin this slice.

Returns

Exceptions

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

Applies to

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET 8, 9, 10

AsSpan(String)

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

Creates a new read-only span over a string.

C#
public static ReadOnlySpan<char> AsSpan(this string? text);
C#
public static ReadOnlySpan<char> AsSpan(this string text);

Parameters

text
String

The target string.

Returns

The read-only span representation of the string.

Remarks

Returns default when text is null.

Applies to

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1

AsSpan(String, Int32)

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.

C#
public static ReadOnlySpan<char> AsSpan(this string? text, int start);
C#
public static ReadOnlySpan<char> AsSpan(this string text, int start);

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

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1

AsSpan<T>(T[], Int32, Int32)

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.

C#
public static Span<T> AsSpan<T>(this T[]? array, int start, int length);
C#
public static Span<T> AsSpan<T>(this T[] array, int start, int length);

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

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1

AsSpan<T>(ArraySegment<T>)

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

Creates a new span over a target array segment.

C#
public static Span<T> AsSpan<T>(this ArraySegment<T> segment);

Type Parameters

T

The type of the array segment.

Parameters

segment
ArraySegment<T>

The array segment to convert.

Returns

The span representation of the array segment.

Applies to

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1

AsSpan<T>(T[])

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

Creates a new span over a target array.

C#
public static Span<T> AsSpan<T>(this T[]? array);
C#
public static Span<T> AsSpan<T>(this T[] array);

Type Parameters

T

The type of the array.

Parameters

array
T[]

The array to convert.

Returns

The span representation of the array.

Applies to

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1

AsSpan<T>(ArraySegment<T>, Index)

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.

C#
public static Span<T> AsSpan<T>(this ArraySegment<T> segment, Index startIndex);

Type Parameters

T

The type of the array segment.

Parameters

segment
ArraySegment<T>

The target array segment.

startIndex
Index

The index at which to begin the Span.

Returns

The span representation of the array segment.

Applies to

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

AsSpan<T>(ArraySegment<T>, Int32)

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.

C#
public static Span<T> AsSpan<T>(this ArraySegment<T> segment, int start);

Type Parameters

T

The type of the array segment.

Parameters

segment
ArraySegment<T>

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

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1

AsSpan<T>(ArraySegment<T>, Range)

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.

C#
public static Span<T> AsSpan<T>(this ArraySegment<T> segment, Range range);

Type Parameters

T

The type of the array segment.

Parameters

segment
ArraySegment<T>

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

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

AsSpan<T>(T[], Index)

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.

C#
public static Span<T> AsSpan<T>(this T[]? array, Index startIndex);
C#
public static Span<T> AsSpan<T>(this T[] array, Index startIndex);

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

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

AsSpan<T>(T[], Int32)

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.

C#
public static Span<T> AsSpan<T>(this T[]? array, int start);
C#
public static Span<T> AsSpan<T>(this T[] array, int start);

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

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1

AsSpan<T>(T[], Range)

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.

C#
public static Span<T> AsSpan<T>(this T[]? array, Range range);
C#
public static Span<T> AsSpan<T>(this T[] array, Range range);

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

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

AsSpan<T>(ArraySegment<T>, Int32, Int32)

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.

C#
public static Span<T> AsSpan<T>(this ArraySegment<T> segment, int start, int length);

Type Parameters

T

The type of the array segment.

Parameters

segment
ArraySegment<T>

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

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1