MemoryMarshal.TryRead<T>(ReadOnlySpan<Byte>, T) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Type Parameters
- T
The type of the structure to retrieve.
Parameters
- source
- ReadOnlySpan<Byte>
A read-only span of bytes.
- value
- T
When the method returns, an instance of T.
Returns
true if the method succeeds in retrieving an instance of the structure; otherwise, false.
Exceptions
T contains references or pointers.
Remarks
T cannot contain pointers or references. It is checked at runtime in order to preserve type safety.