MemoryMarshal.AsBytes 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.
Overloads
AsBytes<T>(ReadOnlySpan<T>) |
Casts a ReadOnlySpan<T> of one primitive type, |
AsBytes<T>(Span<T>) |
Casts a Span<T> of one primitive type, |
AsBytes<T>(ReadOnlySpan<T>)
- Source:
- MemoryMarshal.cs
- Source:
- MemoryMarshal.cs
- Source:
- MemoryMarshal.cs
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
A read-only span of type Byte.
Exceptions
T
contains managed object references.
The Length property of the new ReadOnlySpan<T> would exceed Int32.MaxValue
Remarks
T
cannot contain managed object references. The AsBytes
method performs this check at runtime and throws ArgumentException
if the check fails.
Caution
This method provides a raw binary projection over the original span, including over any private instance fields and other implementation details of type T
. Callers should ensure that their code is resilient to changes in the internal layout of T
.
Applies to
AsBytes<T>(Span<T>)
- Source:
- MemoryMarshal.cs
- Source:
- MemoryMarshal.cs
- Source:
- MemoryMarshal.cs
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
A span of type Byte.
Exceptions
T
contains managed object references.
The Length property of the new ReadOnlySpan<T> would exceed Int32.MaxValue
Remarks
T
cannot contain managed object references. The AsBytes
method performs this check at runtime and throws ArgumentException
if the check fails.
Caution
This method provides a raw binary projection over the original span, including over any private instance fields and other implementation details of type T
. Callers should ensure that their code is resilient to changes in the internal layout of T
.
Applies to
Feedback
https://aka.ms/ContentUserFeedback.
Kommer snart: I hele 2024 udfaser vi GitHub-problemer som feedbackmekanisme for indhold og erstatter det med et nyt feedbacksystem. Du kan få flere oplysninger under:Indsend og få vist feedback om