Bewerken

Share via


MemoryMarshal.CreateSpan<T>(T, Int32) Method

Definition

Creates a new span over a portion of a regular managed object.

public:
generic <typename T>
 static Span<T> CreateSpan(T % reference, int length);
public static Span<T> CreateSpan<T> (ref T reference, int length);
public static Span<T> CreateSpan<T> (scoped ref T reference, int length);
static member CreateSpan : 'T * int -> Span<'T>
Public Shared Function CreateSpan(Of T) (ByRef reference As T, length As Integer) As Span(Of T)

Type Parameters

T

The type of the data items.

Parameters

reference
T

A reference to data.

length
Int32

The number of T elements that reference contains.

Returns

A span.

Remarks

This method can be useful if part of a managed object represents a fixed array.

Warning

This method should be used with caution. It is dangerous because the length argument is not checked. Even though the ref is annotated as scoped, it will be stored into the returned span, and the lifetime of the returned span will not be validated for safety, even by span-aware languages.

Applies to