MemoryMarshal.Cast MemoryMarshal.Cast MemoryMarshal.Cast MemoryMarshal.Cast Method

Definition

Overloads

Cast<TFrom,TTo>(ReadOnlySpan<TFrom>) Cast<TFrom,TTo>(ReadOnlySpan<TFrom>) Cast<TFrom,TTo>(ReadOnlySpan<TFrom>) Cast<TFrom,TTo>(ReadOnlySpan<TFrom>)

Casts a read-only span of one primitive type to a read-only span of another primitive type.

Cast<TFrom,TTo>(Span<TFrom>) Cast<TFrom,TTo>(Span<TFrom>) Cast<TFrom,TTo>(Span<TFrom>) Cast<TFrom,TTo>(Span<TFrom>)

Casts a span of one primitive type to a span of another primitive type.

Cast<TFrom,TTo>(ReadOnlySpan<TFrom>) Cast<TFrom,TTo>(ReadOnlySpan<TFrom>) Cast<TFrom,TTo>(ReadOnlySpan<TFrom>) Cast<TFrom,TTo>(ReadOnlySpan<TFrom>)

Casts a read-only span of one primitive type to a read-only span of another primitive type.

public:
generic <typename TFrom, typename TTo>
 where TFrom : value class where TTo : value class static ReadOnlySpan<TTo> Cast(ReadOnlySpan<TFrom> span);
public static ReadOnlySpan<TTo> Cast<TFrom,TTo> (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)
Public Shared Function Cast(Of TFrom As Structure, TTo As Structure) (span As ReadOnlySpan(Of TFrom)) As ReadOnlySpan(Of TTo)

Type Parameters

TFrom

The type of the source span.

TTo

The type of the target span.

Parameters

span
ReadOnlySpan<TFrom>

The source slice to convert.

Returns

The converted read-only span.

Exceptions

TFrom or TTo contains references or pointers.

Remarks

Neither TFrom nor TTo can contain pointers or references. TFrom and TTo are checked at runtime in order to preserve type safety.

This method is supported only on platforms that support misaligned memory access or when the memory block is aligned by other means.

Cast<TFrom,TTo>(Span<TFrom>) Cast<TFrom,TTo>(Span<TFrom>) Cast<TFrom,TTo>(Span<TFrom>) Cast<TFrom,TTo>(Span<TFrom>)

Casts a span of one primitive type to a span of another primitive type.

public:
generic <typename TFrom, typename TTo>
 where TFrom : value class where TTo : value class static Span<TTo> Cast(Span<TFrom> span);
public static Span<TTo> Cast<TFrom,TTo> (Span<TFrom> span) where TFrom : struct where TTo : struct;
static member Cast : Span<'From (requires 'From : struct)> -> Span<'o (requires 'o : struct)> (requires 'From : struct and 'o : struct)
Public Shared Function Cast(Of TFrom As Structure, TTo As Structure) (span As Span(Of TFrom)) As Span(Of TTo)

Type Parameters

TFrom

The type of the source span.

TTo

The type of the target span.

Parameters

span
Span<TFrom>

The source slice to convert.

Returns

Span<TTo>

The converted span.

Exceptions

TFrom or TTo contains references or pointers.

Remarks

Neither TFrom nor TTo can contain pointers or references. TFrom and TTo are checked at runtime in order to preserve type safety.

The cast occurs in an unchecked context. If the range of TTo is less than the range of TFrom, data loss can occur. For example, if TFrom is Int64, one of the ReadOnlySpan<Int32> values is 0x100001111110F0F, and TTo is Int32, the resulting value is 11110F0F.

This method is supported only on platforms that support misaligned memory access or when the memory block is aligned by other means.

Applies to