MemoryExtensions.AsMemory Method

Definition

Overloads

AsMemory(String)

Creates a new ReadOnlyMemory<Char> over the portion of the target string.

AsMemory(String, Index)

Creates a new ReadOnlyMemory<Char> over a portion of the target string starting at a specified index.

AsMemory(String, Int32)

Creates a new ReadOnlyMemory<Char> over a portion of the target string starting at a specified character position.

AsMemory(String, Range)

Creates a new ReadOnlyMemory<Char> over a specified range of the target string.

AsMemory(String, Int32, Int32)

Creates a new ReadOnlyMemory<Char> over a portion of the target string beginning at a specified position with a length.

AsMemory<T>(ArraySegment<T>)

Creates a new memory region over the portion of the target array segment.

AsMemory<T>(T[])

Creates a new memory region over the target array.

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

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

AsMemory<T>(T[], Index)

Creates a new memory region over the portion of the target array starting at a specified index to the end of the array.

AsMemory<T>(T[], Int32)

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

AsMemory<T>(T[], Range)

Creates a new memory region over the portion of the target array beginning at inclusive start index of the range and ending at the exclusive end index of the range.

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

Creates a new memory region over the portion of the target array segment beginning at a specified position with a specified length.

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

Creates a new memory region over the portion of the target array beginning at a specified position with a specified length.

AsMemory(String)

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

Creates a new ReadOnlyMemory<Char> over the portion of the target string.

public static ReadOnlyMemory<char> AsMemory (this string? text);
public static ReadOnlyMemory<char> AsMemory (this string text);

Parameters

text
String

The target string.

Returns

The read-only character memory representation of the string, or default if text is null.

Remarks

Returns default when text is null.

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

AsMemory(String, Index)

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

Creates a new ReadOnlyMemory<Char> over a portion of the target string starting at a specified index.

public static ReadOnlyMemory<char> AsMemory (this string? text, Index startIndex);
public static ReadOnlyMemory<char> AsMemory (this string text, Index startIndex);

Parameters

text
String

The target string.

startIndex
Index

The index at which to begin this slice.

Returns

The read-only character memory representation of the string.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Standard 2.1

AsMemory(String, Int32)

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

Creates a new ReadOnlyMemory<Char> over a portion of the target string starting at a specified character position.

public static ReadOnlyMemory<char> AsMemory (this string? text, int start);
public static ReadOnlyMemory<char> AsMemory (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 character memory representation of the string, or default if text is null.

Exceptions

start is not in the range of text (start is < 0 or > text.Length).

Remarks

Returns default when text is null.

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

AsMemory(String, Range)

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

Creates a new ReadOnlyMemory<Char> over a specified range of the target string.

public static ReadOnlyMemory<char> AsMemory (this string? text, Range range);
public static ReadOnlyMemory<char> AsMemory (this string text, Range range);

Parameters

text
String

The target string.

range
Range

The range that indicates the start and length of the sliced string.

Returns

The read-only character memory representation of the string.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Standard 2.1

AsMemory(String, Int32, Int32)

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

Creates a new ReadOnlyMemory<Char> over a portion of the target string beginning at a specified position with a length.

public static ReadOnlyMemory<char> AsMemory (this string? text, int start, int length);
public static ReadOnlyMemory<char> AsMemory (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 character memory representation of the string, or default if text is null.

Exceptions

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

Remarks

Returns default when text is null.

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

AsMemory<T>(ArraySegment<T>)

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

Creates a new memory region over the portion of the target array segment.

public static Memory<T> AsMemory<T> (this ArraySegment<T> segment);

Type Parameters

T

The type of the segment.

Parameters

segment
ArraySegment<T>

The segment to convert.

Returns

The memory representation of the segment.

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

AsMemory<T>(T[])

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

Creates a new memory region over the target array.

public static Memory<T> AsMemory<T> (this T[]? array);
public static Memory<T> AsMemory<T> (this T[] array);

Type Parameters

T

The type of the array.

Parameters

array
T[]

The array to convert.

Returns

The memory representation of the whole or part of the array.

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

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

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

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

public static Memory<T> AsMemory<T> (this ArraySegment<T> segment, int start);

Type Parameters

T

The type of the array.

Parameters

segment
ArraySegment<T>

The target array segment.

start
Int32

The index at which to begin the memory.

Returns

The memory representation of the whole or part of the array.

Exceptions

segment is covariant, and the type of segment is not exactly T[].

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

Remarks

Returns default when segment is null.

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

AsMemory<T>(T[], Index)

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

Creates a new memory region over the portion of the target array starting at a specified index to the end of the array.

public static Memory<T> AsMemory<T> (this T[]? array, Index startIndex);
public static Memory<T> AsMemory<T> (this T[] array, Index startIndex);

Type Parameters

T

The type of the array.

Parameters

array
T[]

The array to convert.

startIndex
Index

The first position of the array.

Returns

The memory representation of the whole or part of the array.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Standard 2.1

AsMemory<T>(T[], Int32)

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

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

public static Memory<T> AsMemory<T> (this T[]? array, int start);
public static Memory<T> AsMemory<T> (this T[] array, int start);

Type Parameters

T

The type of the array.

Parameters

array
T[]

The target array.

start
Int32

The index at which to begin the memory.

Returns

The memory representation of the whole or part of the array.

Exceptions

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

start index less than 0 or greater than array.Length.

Remarks

Returns default when array is null.

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

AsMemory<T>(T[], Range)

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

Creates a new memory region over the portion of the target array beginning at inclusive start index of the range and ending at the exclusive end index of the range.

public static Memory<T> AsMemory<T> (this T[]? array, Range range);
public static Memory<T> AsMemory<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 to convert from the array.

Returns

The memory representation of the whole or part of the array.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Standard 2.1

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

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

Creates a new memory region over the portion of the target array segment beginning at a specified position with a specified length.

public static Memory<T> AsMemory<T> (this ArraySegment<T> segment, int start, int length);

Type Parameters

T

The type of the array.

Parameters

segment
ArraySegment<T>

The target array segment.

start
Int32

The index at which to begin the memory.

length
Int32

The number of items in the memory.

Returns

The memory representation of the whole or part 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 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

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

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

Creates a new memory region over the portion of the target array beginning at a specified position with a specified length.

public static Memory<T> AsMemory<T> (this T[]? array, int start, int length);
public static Memory<T> AsMemory<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 memory region.

length
Int32

The number of items in the memory region.

Returns

The memory representation of the whole or part 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 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