Breyta

Deila með


MemoryMarshal.AsRef Method

Definition

Overloads

AsRef<T>(ReadOnlySpan<Byte>)

Reinterprets a read-only span of bytes as a read-only reference to the structure of type T.

AsRef<T>(Span<Byte>)

Reinterprets a span of bytes as a reference to the structure of type T.

AsRef<T>(ReadOnlySpan<Byte>)

Source:
MemoryMarshal.cs
Source:
MemoryMarshal.cs
Source:
MemoryMarshal.cs

Reinterprets a read-only span of bytes as a read-only reference to the structure of type T.

public:
generic <typename T>
 where T : value class static T& ^ AsRef(ReadOnlySpan<System::Byte> span);
public static ref readonly T AsRef<T> (ReadOnlySpan<byte> span) where T : struct;
static member AsRef : ReadOnlySpan<byte> -> 'T (requires 'T : struct)
Public Shared Function AsRef(Of T As Structure) (span As ReadOnlySpan(Of Byte)) As T

Type Parameters

T

The type of the returned reference.

Parameters

span
ReadOnlySpan<Byte>

The read-only span to reinterpret.

Returns

T

The read-only reference to the structure of type T.

Exceptions

T contains managed object references.

Remarks

T cannot contain managed object references. The AsRef method performs this check at runtime and throws ArgumentException if the check fails.

This method is supported only on platforms that support misaligned memory access or when the memory block is aligned by other means.

Applies to

AsRef<T>(Span<Byte>)

Source:
MemoryMarshal.cs
Source:
MemoryMarshal.cs
Source:
MemoryMarshal.cs

Reinterprets a span of bytes as a reference to the structure of type T.

public:
generic <typename T>
 where T : value class static T % AsRef(Span<System::Byte> span);
public static ref T AsRef<T> (Span<byte> span) where T : struct;
static member AsRef : Span<byte> -> 'T (requires 'T : struct)
Public Shared Function AsRef(Of T As Structure) (span As Span(Of Byte)) As T

Type Parameters

T

The type of the returned reference.

Parameters

span
Span<Byte>

The span to reinterpret.

Returns

T

The reference to the structure of type T.

Exceptions

T contains managed object references.

Remarks

T cannot contain managed object references. The AsRef method performs this check at runtime and throws ArgumentException if the check fails.

This method is supported only on platforms that support misaligned memory access or when the memory block is aligned by other means.

Applies to