Edit

Share via


Memory<T> Constructors

Definition

Overloads

Memory<T>(T[])

Creates a new Memory<T> object over the entirety of a specified array.

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

Creates a new Memory<T> object that includes a specified number of elements of an array beginning at a specified index.

Memory<T>(T[])

Source:
Memory.cs
Source:
Memory.cs
Source:
Memory.cs

Creates a new Memory<T> object over the entirety of a specified array.

C#
public Memory(T[]? array);
C#
public Memory(T[] array);

Parameters

array
T[]

The array from which to create the Memory<T> object.

Exceptions

T is a reference type, and array is not an array of type T.

-or-

The array is covariant.

Remarks

If array is null, this constructor returns a Memory<T> object with a default<T> value.

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

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

Source:
Memory.cs
Source:
Memory.cs
Source:
Memory.cs

Creates a new Memory<T> object that includes a specified number of elements of an array beginning at a specified index.

C#
public Memory(T[]? array, int start, int length);
C#
public Memory(T[] array, int start, int length);

Parameters

array
T[]

The source array.

start
Int32

The index of the first element to include in the new Memory<T>.

length
Int32

The number of elements to include in the new Memory<T>.

Exceptions

array is null, but start or length is non-zero.

-or-

start is outside the bounds of the array.

-or-

start and length exceeds the number of elements in the array.

T is a reference type, and array is not an array of type T.

Remarks

If array is null, this constructor returns a Memory<T> object with a default<T> value.

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