MemoryMarshal.AsBytes Method

Definition

Overloads

AsBytes<T>(ReadOnlySpan<T>)

Casts a ReadOnlySpan<T> of one primitive type, T, to a ReadOnlySpan<Byte>.

AsBytes<T>(Span<T>)

Casts a Span<T> of one primitive type, T, to a Span<Byte>.

AsBytes<T>(ReadOnlySpan<T>)

Casts a ReadOnlySpan<T> of one primitive type, T, to a ReadOnlySpan<Byte>.

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

Type Parameters

T

The type of items in the read-only span.

Parameters

span
ReadOnlySpan<T>

The source slice to convert.

Returns

ReadOnlySpan<Byte>

A read-only span of type Byte.

Exceptions

T contains references or pointers.

The Length property of the new ReadOnlySpan<T> would exceed MaxValue

Remarks

T cannot contain pointers or references. T is checked at runtime in order to preserve type safety.

Applies to

AsBytes<T>(Span<T>)

Casts a Span<T> of one primitive type, T, to a Span<Byte>.

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

Type Parameters

T

The type of items in the span.

Parameters

span
Span<T>

The source slice to convert.

Returns

Span<Byte>

A span of type Byte.

Exceptions

T contains references or pointers.

The Length property of the new Span<T> would exceed MaxValue

Remarks

T cannot contain pointers or references. T is checked at runtime in order to preserve type safety.

Applies to