Table of Contents

Method TryFormat

Namespace
Terminal.Gui.Drawing
Assembly
Terminal.Gui.dll

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters

destination Span<char>
charsWritten int
format ReadOnlySpan<char>
provider IFormatProvider

Returns

bool

Remarks

This method should be used only when absolutely necessary, because it always has more overhead than ToString(string?, IFormatProvider?), as this method results in an intermediate allocation of one or more instances of string and a copy of that string to destination if formatting was successful.
When possible, use ToString(string?, IFormatProvider?), which attempts to avoid intermediate allocations.

This method only returns true and with its output written to destination if the formatted string, in its entirety, will fit in destination. If the resulting formatted string is too large to fit in destination, the result will be false and destination will be unaltered.

The resulting formatted string may be shorter than destination. When this method returns true, use charsWritten when handling the value of destination.

TryFormat(Span<byte>, out int, ReadOnlySpan<char>, IFormatProvider?)

public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters

utf8Destination Span<byte>
bytesWritten int
format ReadOnlySpan<char>
provider IFormatProvider

Returns

bool

Remarks

Use of this method involves a stack allocation of utf8Destination.Length * 2 bytes. Use of the overload taking a char span is recommended.