編集

次の方法で共有


ListExtensions.AsSpan<T>(List<T>) Method

Definition

Creates a new Span<T> over an input List<T> instance.

public static Span<T> AsSpan<T> (this System.Collections.Generic.List<T>? list);
static member AsSpan : System.Collections.Generic.List<'T> -> Span<'T>
<Extension()>
Public Function AsSpan(Of T) (list As List(Of T)) As Span(Of T)

Type Parameters

T

The type of elements in the input List<T> instance.

Parameters

list
List<T>

The input List<T> instance.

Returns

Span<T>

A Span<T> instance with the values of list.

Remarks

Note that the returned Span<T> is only guaranteed to be valid as long as the items within list are not modified. Doing so might cause the List<T> to swap its internal buffer, causing the returned Span<T> to become out of date. That means that in this scenario, the Span<T> would end up wrapping an array no longer in use. Always make sure to use the returned Span<T> while the target List<T> is not modified.

Applies to