MemoryMarshal.Read<T>(ReadOnlySpan<Byte>) 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.
Reads a structure of type T
out of a read-only span of bytes.
public:
generic <typename T>
where T : value class static T Read(ReadOnlySpan<System::Byte> source);
public static T Read<T> (ReadOnlySpan<byte> source) where T : struct;
static member Read : ReadOnlySpan<byte> -> 'T (requires 'T : struct)
Public Shared Function Read(Of T As Structure) (source As ReadOnlySpan(Of Byte)) As T
Type Parameters
- T
The type of the item to retrieve from the read-only span.
Parameters
- source
- ReadOnlySpan<Byte>
A read-only span.
Returns
The structure retrieved from the read-only span.
Exceptions
T
contains managed object references.
source
is smaller than T
's length in bytes.
Remarks
T
cannot contain managed object references. The Read
method performs this check at runtime and throws ArgumentException
if the check fails.
Caution
This method initializes an instance of T
, including private instance fields and other implementation details, from the raw binary contents of the source span. Callers must ensure that the contents of the source span are well-formed with regard to T
's internal invariants.