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

Definition

Creates a new read-only span over a portion of a regular managed object.

public:
generic <typename T>
 static ReadOnlySpan<T> CreateReadOnlySpan(T % reference, int length);
public static ReadOnlySpan<T> CreateReadOnlySpan<T> (ref T reference, int length);
static member CreateReadOnlySpan : 'T * int -> ReadOnlySpan<'T>
Public Shared Function CreateReadOnlySpan(Of T) (ByRef reference As T, length As Integer) As ReadOnlySpan(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 read-only 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. In addition, the lifetime of the returned span is not validated for safety by span-aware languages.

Applies to