ReadOnlySpan<T>.ToArray Method

Definition

Copies the contents of this read-only span into a new array.

C#
public T[] ToArray();

Returns

T[]

An array containing the data in the current span.

Remarks

This method performs a heap allocation and data copy, and therefore, should be avoided if possible. It it sometimes necessary when APIs that support ReadOnlySpan<T> are not available, but APIs that work with arrays are.

Applies to

Producto Versiones
.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