EncodingExtensions.GetBytes Method

Definition

Overloads

GetBytes(Encoding, ReadOnlySequence<Char>)

Encodes the specified ReadOnlySequence<T> into a Byte array using the specified Encoding.

GetBytes(Encoding, ReadOnlySequence<Char>, IBufferWriter<Byte>)

Decodes the specified ReadOnlySequence<T> to bytes using the specified Encoding and writes the result to writer.

GetBytes(Encoding, ReadOnlySequence<Char>, Span<Byte>)

Encodes the specified ReadOnlySequence<T> to bytes using the specified Encoding and outputs the result to bytes.

GetBytes(Encoding, ReadOnlySpan<Char>, IBufferWriter<Byte>)

Encodes the specified ReadOnlySpan<T> to bytes using the specified Encoding and writes the result to writer.

GetBytes(Encoding, ReadOnlySequence<Char>)

Source:
EncodingExtensions.cs
Source:
EncodingExtensions.cs
Source:
EncodingExtensions.cs

Encodes the specified ReadOnlySequence<T> into a Byte array using the specified Encoding.

public static byte[] GetBytes (this System.Text.Encoding encoding, in System.Buffers.ReadOnlySequence<char> chars);

Parameters

encoding
Encoding

The encoding that represents how the data in chars should be encoded.

chars
ReadOnlySequence<Char>

The sequence to encode to bytes.

Returns

Byte[]

A Byte array that represents the encoded contents of chars.

Exceptions

chars contains data that cannot be encoded and encoding is configured to throw when such data is seen.

Applies to

.NET 9 e altre versioni
Prodotto Versioni
.NET 5, 6, 7, 8, 9

GetBytes(Encoding, ReadOnlySequence<Char>, IBufferWriter<Byte>)

Source:
EncodingExtensions.cs
Source:
EncodingExtensions.cs
Source:
EncodingExtensions.cs

Decodes the specified ReadOnlySequence<T> to bytes using the specified Encoding and writes the result to writer.

public static long GetBytes (this System.Text.Encoding encoding, in System.Buffers.ReadOnlySequence<char> chars, System.Buffers.IBufferWriter<byte> writer);

Parameters

encoding
Encoding

The encoding that represents how the data in chars should be encoded.

chars
ReadOnlySequence<Char>

The ReadOnlySequence<T> whose contents should be encoded.

writer
IBufferWriter<Byte>

The buffer to which the encoded bytes will be written.

Returns

The number of bytes written to writer.

Exceptions

chars contains data that cannot be encoded and encoding is configured to throw when such data is seen.

Applies to

.NET 9 e altre versioni
Prodotto Versioni
.NET 5, 6, 7, 8, 9

GetBytes(Encoding, ReadOnlySequence<Char>, Span<Byte>)

Source:
EncodingExtensions.cs
Source:
EncodingExtensions.cs
Source:
EncodingExtensions.cs

Encodes the specified ReadOnlySequence<T> to bytes using the specified Encoding and outputs the result to bytes.

public static int GetBytes (this System.Text.Encoding encoding, in System.Buffers.ReadOnlySequence<char> chars, Span<byte> bytes);

Parameters

encoding
Encoding

The encoding that represents how the data in chars should be encoded.

chars
ReadOnlySequence<Char>

The sequence to encode to bytes.

bytes
Span<Byte>

The destination buffer to which the encoded bytes will be written.

Returns

The number of bytes written to bytes.

Exceptions

bytes is not large enough to contain the encoded form of chars.

chars contains data that cannot be encoded and encoding is configured to throw when such data is seen.

Applies to

.NET 9 e altre versioni
Prodotto Versioni
.NET 5, 6, 7, 8, 9

GetBytes(Encoding, ReadOnlySpan<Char>, IBufferWriter<Byte>)

Source:
EncodingExtensions.cs
Source:
EncodingExtensions.cs
Source:
EncodingExtensions.cs

Encodes the specified ReadOnlySpan<T> to bytes using the specified Encoding and writes the result to writer.

public static long GetBytes (this System.Text.Encoding encoding, ReadOnlySpan<char> chars, System.Buffers.IBufferWriter<byte> writer);

Parameters

encoding
Encoding

The encoding that represents how the data in chars should be encoded.

chars
ReadOnlySpan<Char>

The sequence to encode to bytes.

writer
IBufferWriter<Byte>

The buffer to which the encoded bytes will be written.

Returns

The number of bytes written to writer.

Exceptions

chars contains data that cannot be encoded and encoding is configured to throw when such data is seen.

Applies to

.NET 9 e altre versioni
Prodotto Versioni
.NET 5, 6, 7, 8, 9