MemoryMarshal.Cast Método
Definição
Sobrecargas
| Cast<TFrom,TTo>(ReadOnlySpan<TFrom>) |
Converte uma extensão de somente leitura de um tipo primitivo em uma extensão de outro tipo primitivo.Casts a read-only span of one primitive type to a read-only span of another primitive type. |
| Cast<TFrom,TTo>(Span<TFrom>) |
Converte um período de um tipo primitivo em um período de outro tipo primitivo.Casts a span of one primitive type to a span of another primitive type. |
Cast<TFrom,TTo>(ReadOnlySpan<TFrom>)
Converte uma extensão de somente leitura de um tipo primitivo em uma extensão de outro tipo primitivo.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)
Parâmetros de tipo
- TFrom
O tipo do span de origem.The type of the source span.
- TTo
O tipo do span de destino.The type of the target span.
Parâmetros
- span
- ReadOnlySpan<TFrom>
A fatia de origem a ser convertida.The source slice to convert.
Retornos
- ReadOnlySpan<TTo>
A extensão de somente leitura convertida.The converted read-only span.
Exceções
TFrom ou TTo contém referências ou ponteiros.TFrom or TTo contains references or pointers.
Comentários
Nem TFrom nem TTo pode conter indicações ou referências.Neither TFrom nor TTo can contain pointers or references. TFrom e TTo são verificados em tempo de execução para preservar a segurança do tipo.TFrom and TTo are checked at runtime in order to preserve type safety.
Esse método tem suporte apenas em plataformas que dão suporte ao acesso de memória desalinhado ou quando o bloco de memória está alinhado por outros meios.This method is supported only on platforms that support misaligned memory access or when the memory block is aligned by other means.
Aplica-se a
Cast<TFrom,TTo>(Span<TFrom>)
Converte um período de um tipo primitivo em um período de outro tipo primitivo.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)
Parâmetros de tipo
- TFrom
O tipo do span de origem.The type of the source span.
- TTo
O tipo do span de destino.The type of the target span.
Parâmetros
- span
- Span<TFrom>
A fatia de origem a ser convertida.The source slice to convert.
Retornos
- Span<TTo>
A extensão convertida.The converted span.
Exceções
TFrom ou TTo contém referências ou ponteiros.TFrom or TTo contains references or pointers.
Comentários
Nem TFrom nem TTo pode conter indicações ou referências.Neither TFrom nor TTo can contain pointers or references. TFrom e TTo são verificados em tempo de execução para preservar a segurança do tipo.TFrom and TTo are checked at runtime in order to preserve type safety.
Se os tamanhos dos dois tipos forem diferentes, a conversão combinará ou dividirá os valores, o que leva a uma alteração no comprimento.If the sizes of the two types are different, the cast combines or splits values, which leads to a change in length.
Por exemplo, se TFrom é Int64 , ReadOnlySpan<Int64> contém um único valor, 0x0100001111110F0F e TTo é Int32 , o resultado ReadOnlySpan<Int32> contém dois valores.For example, if TFrom is Int64, the ReadOnlySpan<Int64> contains a single value, 0x0100001111110F0F, and TTo is Int32, the resulting ReadOnlySpan<Int32> contains two values. Os valores são 0x11110F0F e 0x01000011 em uma arquitetura little-endian, como x86.The values are 0x11110F0F and 0x01000011 on a little-endian architecture, such as x86. Em uma arquitetura big endian, a ordem dos dois valores é revertida, ou seja, 0x01000011, seguida de 0x11110F0F.On a big-endian architecture, the order of the two values is reversed, i.e. 0x01000011, followed by 0x11110F0F.
Como outro exemplo, se TFrom for Int32 , o ReadOnlySpan<Int32> contém os valores de 1, 2 e 3, e TTo é Int64 , o resultado ReadOnlySpan<Int64> contém um único valor: 0x0000000200000001 em uma arquitetura little-endian e 0x0000000100000002 em uma arquitetura big-endian.As another example, if TFrom is Int32, the ReadOnlySpan<Int32> contains the values of 1, 2 and 3, and TTo is Int64, the resulting ReadOnlySpan<Int64> contains a single value: 0x0000000200000001 on a little-endian architecture and 0x0000000100000002 on a big-endian architecture.
Esse método tem suporte apenas em plataformas que dão suporte ao acesso de memória desalinhado ou quando o bloco de memória está alinhado por outros meios.This method is supported only on platforms that support misaligned memory access or when the memory block is aligned by other means.