Modifier

Partager via


ReadOnlySpanExtensions.Cast<TFrom,TTo> Method

Definition

Casts a ReadOnlySpan<T> of one primitive type TFrom to another primitive type TTo. These types may not contain pointers or references. This is checked at runtime in order to preserve type safety.

public static ReadOnlySpan<TTo> Cast<TFrom,TTo> (this ReadOnlySpan<TFrom> span) where TFrom : struct where TTo : struct;
static member Cast : ReadOnlySpan<'From (requires 'From : struct)> -> ReadOnlySpan<'o (requires 'o : struct)> (requires 'From : struct and 'o : struct)
<Extension()>
Public Function Cast(Of TFrom As Structure, TTo As Structure) (span As ReadOnlySpan(Of TFrom)) As ReadOnlySpan(Of TTo)

Type Parameters

TFrom

The type of items in the source ReadOnlySpan<T>.

TTo

The type of items in the destination ReadOnlySpan<T>.

Parameters

span
ReadOnlySpan<TFrom>

The source slice, of type TFrom.

Returns

A ReadOnlySpan<T> of type TTo

Exceptions

Thrown when TFrom or TTo contains pointers.

Remarks

Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means.

Applies to