Table of Contents

Method Cast

Namespace
Zyl.ExSpans
Assembly
ExSpans.Core.dll

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

Casts a ExSpan 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. (将一种基元类型 TFrom的ExSpan 转换为另一种基元类型 TTo. 该类型不能包含指针或引用。它会在运行时检查这一点,以保护类型安全).

public static ExSpan<TTo> Cast<TFrom, TTo>(ExSpan<TFrom> span) where TFrom : struct where TTo : struct

Parameters

span ExSpan<TFrom>

The source slice, of type TFrom (TFrom 类型的源切片).

Returns

ExSpan<TTo>

The converted span (转换后的跨度).

Type Parameters

TFrom

The element type of the source span (源跨度的元素类型).

TTo

The element type of the target span (目标跨度的元素类型).

Remarks

Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means (仅当支持未对齐内存访问的平台或内存块通过其他方式对齐时, 才支持此方法).

Exceptions

ArgumentException

Thrown when TFrom or TTo contains pointers.

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

Casts a ReadOnlyExSpan 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. (将一种基元类型TFrom的 ReadOnlyExSpan 转换为另一种基元类型 TTo. 该类型不能包含指针或引用。它会在运行时检查这一点,以保护类型安全).

public static ReadOnlyExSpan<TTo> Cast<TFrom, TTo>(ReadOnlyExSpan<TFrom> span) where TFrom : struct where TTo : struct

Parameters

span ReadOnlyExSpan<TFrom>

The source slice, of type TFrom (TFrom 类型的源切片).

Returns

ReadOnlyExSpan<TTo>

The converted read-only span (转换后的只读跨度).

Type Parameters

TFrom

The element type of the source span (源跨度的元素类型).

TTo

The element type of the target span (目标跨度的元素类型).

Remarks

Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means (仅当支持未对齐内存访问的平台或内存块通过其他方式对齐时, 才支持此方法).

Exceptions

ArgumentException

Thrown when TFrom or TTo contains pointers.