MemoryMarshal.TryRead<T>(ReadOnlySpan<Byte>, T) 方法

定义

尝试从字节的只读范围中读取 T 类型的结构。Tries to read a structure of type T from a read-only span of bytes.

public:
generic <typename T>
 where T : value class static bool TryRead(ReadOnlySpan<System::Byte> source, [Runtime::InteropServices::Out] T % value);
public static bool TryRead<T> (ReadOnlySpan<byte> source, out T value) where T : struct;
static member TryRead : ReadOnlySpan<byte> * 'T -> bool (requires 'T : struct)
Public Shared Function TryRead(Of T As Structure) (source As ReadOnlySpan(Of Byte), ByRef value As T) As Boolean

类型参数

T

要检索的结构的类型。The type of the structure to retrieve.

参数

source
ReadOnlySpan<Byte>

字节的只读范围。A read-only span of bytes.

value
T

此方法返回时,为 T 的实例。When the method returns, an instance of T.

返回

Boolean

如果此方法成功检索到结构的实例,则为 true;否则为 falsetrue if the method succeeds in retrieving an instance of the structure; otherwise, false.

例外

T 包含引用或指针。T contains references or pointers.

注解

T 不能包含指针或引用。T cannot contain pointers or references. 它在运行时进行检查,以便保持类型安全性。It is checked at runtime in order to preserve type safety.

适用于