Edit

Share via


CollectionsMarshal.AsBytes(BitArray) Method

Definition

Gets a Span<T> view over a BitArray's data.

public:
 static Span<System::Byte> AsBytes(System::Collections::BitArray ^ array);
public static Span<byte> AsBytes(System.Collections.BitArray? array);
static member AsBytes : System.Collections.BitArray -> Span<byte>
Public Shared Function AsBytes (array As BitArray) As Span(Of Byte)

Parameters

array
BitArray

The BitArray whose backing storage should be viewed.

Returns

Remarks

The BitArray may have more capacity than is required to store the number of bits represented by Length.

The returned span's Length will be the smallest number of bytes capable of representing that length. If the BitArray's length is not evenly divisible by 8, the last byte of the span may contain extraneous bits that do not represent elements in the BitArray. These can be ignored.

The length of the BitArray should not be changed while the resulting Span<T> is in use. After such a change, the span may no longer refer to the BitArray's backing storage.

Applies to