Encoding.TryGetBytes 方法

定义

如果目标足够大,则从指定的只读范围将一组字符编码为字节范围。

public:
 virtual bool TryGetBytes(ReadOnlySpan<char> chars, Span<System::Byte> bytes, [Runtime::InteropServices::Out] int % bytesWritten);
public virtual bool TryGetBytes (ReadOnlySpan<char> chars, Span<byte> bytes, out int bytesWritten);
abstract member TryGetBytes : ReadOnlySpan<char> * Span<byte> * int -> bool
override this.TryGetBytes : ReadOnlySpan<char> * Span<byte> * int -> bool
Public Overridable Function TryGetBytes (chars As ReadOnlySpan(Of Char), bytes As Span(Of Byte), ByRef bytesWritten As Integer) As Boolean

参数

chars
ReadOnlySpan<Char>

包含要编码的字符集的范围。

bytes
Span<Byte>

用于保存已编码字节的字节范围。

bytesWritten
Int32

成功完成操作后,编码为 bytes的字节数。

返回

true 如果所有字符都编码到目标中,则为 ; false 如果目标太小,无法包含所有编码的字节,则为 。

适用于