Method AsRef
AsRef<T>(ExSpan<byte>)
Re-interprets a span of bytes as a reference to structure of type T
.
The type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
(将字节跨度重新解释为对 T
类型结构体的引用. 该类型不能包含指针或引用. 它会在运行时检查这一点, 以保护类型安全).
public static ref T AsRef<T>(ExSpan<byte> span) where T : struct
Parameters
Returns
- T
The reference to the structure of type
T
(对T
类型结构的引用).
Type Parameters
T
The element type (元素的类型).
Remarks
Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means (仅当支持未对齐内存访问的平台或内存块通过其他方式对齐时, 才支持此方法).
Exceptions
- ArgumentException
T contains managed object references.
AsRef<T>(ReadOnlyExSpan<byte>)
Re-interprets a read-only span of bytes as a reference to structure of type T
.
The type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
(将字节只读跨度重新解释为对 T
类型结构体的引用. 该类型不能包含指针或引用. 它会在运行时检查这一点, 以保护类型安全).
public static ref readonly T AsRef<T>(ReadOnlyExSpan<byte> span) where T : struct
Parameters
span
ReadOnlyExSpan<byte>The source span (源跨度).
Returns
- T
The reference to the structure of type
T
(对T
类型结构的引用).
Type Parameters
T
The element type (元素的类型).
Remarks
Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means (仅当支持未对齐内存访问的平台或内存块通过其他方式对齐时, 才支持此方法).
Exceptions
- ArgumentException
T contains managed object references.