Method TryFormat
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
destinationSpan<char>charsWrittenintformatReadOnlySpan<char>providerIFormatProvider
Returns
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
utf8DestinationSpan<byte>bytesWrittenintformatReadOnlySpan<char>providerIFormatProvider
Returns
Remarks
Use of this method involves a stack allocation of utf8Destination.Length * 2 bytes. Use of
the overload taking a char span is recommended.