MemoryExtensions.TryWrite Method

Definition

Overloads

TryWrite(Span<Char>, IFormatProvider, CompositeFormat, Int32, Object[])

Writes the CompositeFormat string to the character span, substituting the format item or items with the string representation of the corresponding arguments.

TryWrite(Span<Char>, MemoryExtensions+TryWriteInterpolatedStringHandler, Int32)

Writes the specified interpolated string to the character span.

TryWrite(Span<Char>, IFormatProvider, MemoryExtensions+TryWriteInterpolatedStringHandler, Int32)

Writes the specified interpolated string to the character span.

TryWrite(Span<Char>, IFormatProvider, CompositeFormat, Int32, ReadOnlySpan<Object>)

Writes the CompositeFormat string to the character span, substituting the format item or items with the string representation of the corresponding arguments.

TryWrite<TArg0,TArg1,TArg2>(Span<Char>, IFormatProvider, CompositeFormat, Int32, TArg0, TArg1, TArg2)

Writes the CompositeFormat string to the character span, substituting the format item or items with the string representation of the corresponding arguments.

TryWrite<TArg0,TArg1>(Span<Char>, IFormatProvider, CompositeFormat, Int32, TArg0, TArg1)

Writes the CompositeFormat string to the character span, substituting the format item or items with the string representation of the corresponding arguments.

TryWrite<TArg0>(Span<Char>, IFormatProvider, CompositeFormat, Int32, TArg0)

Writes the CompositeFormat string to the character span, substituting the format item or items with the string representation of the corresponding arguments.

TryWrite(Span<Char>, IFormatProvider, CompositeFormat, Int32, Object[])

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Writes the CompositeFormat string to the character span, substituting the format item or items with the string representation of the corresponding arguments.

public static bool TryWrite (this Span<char> destination, IFormatProvider? provider, System.Text.CompositeFormat format, out int charsWritten, params object?[] args);

Parameters

destination
Span<Char>

The span to which the string should be formatted.

provider
IFormatProvider

An object that supplies culture-specific formatting information.

charsWritten
Int32

When this method returns, contains the number of characters written to the span.

args
Object[]

An array of objects to format.

Returns

true if the entire interpolated string could be formatted successfully; otherwise, false.

Exceptions

format or args is null.

The index of a format item is greater than or equal to the number of supplied arguments.

Applies to

.NET 9 and .NET 8
Product Versions
.NET 8, 9

TryWrite(Span<Char>, MemoryExtensions+TryWriteInterpolatedStringHandler, Int32)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Writes the specified interpolated string to the character span.

public static bool TryWrite (this Span<char> destination, ref MemoryExtensions.TryWriteInterpolatedStringHandler handler, out int charsWritten);

Parameters

destination
Span<Char>

The span to which the interpolated string should be formatted.

handler
MemoryExtensions.TryWriteInterpolatedStringHandler

The interpolated string, passed by reference.

charsWritten
Int32

When this method returns, contains the number of characters written to the span.

Returns

true if the entire interpolated string could be formatted successfully; otherwise, false.

Applies to

.NET 9 and other versions
Product Versions
.NET 6, 7, 8, 9

TryWrite(Span<Char>, IFormatProvider, MemoryExtensions+TryWriteInterpolatedStringHandler, Int32)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Writes the specified interpolated string to the character span.

public static bool TryWrite (this Span<char> destination, IFormatProvider? provider, ref MemoryExtensions.TryWriteInterpolatedStringHandler handler, out int charsWritten);

Parameters

destination
Span<Char>

The span to which the interpolated string should be formatted.

provider
IFormatProvider

An object that supplies culture-specific formatting information.

handler
MemoryExtensions.TryWriteInterpolatedStringHandler

The interpolated string, passed by reference.

charsWritten
Int32

When this method returns, contains the number of characters written to the span.

Returns

true if the entire interpolated string could be formatted successfully; otherwise, false.

Applies to

.NET 9 and other versions
Product Versions
.NET 6, 7, 8, 9

TryWrite(Span<Char>, IFormatProvider, CompositeFormat, Int32, ReadOnlySpan<Object>)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Writes the CompositeFormat string to the character span, substituting the format item or items with the string representation of the corresponding arguments.

public static bool TryWrite (this Span<char> destination, IFormatProvider? provider, System.Text.CompositeFormat format, out int charsWritten, ReadOnlySpan<object?> args);
public static bool TryWrite (this Span<char> destination, IFormatProvider? provider, System.Text.CompositeFormat format, out int charsWritten, scoped ReadOnlySpan<object?> args);

Parameters

destination
Span<Char>

The span to which the string should be formatted.

provider
IFormatProvider

An object that supplies culture-specific formatting information.

charsWritten
Int32

When this method returns, contains the number of characters written to the span.

args
ReadOnlySpan<Object>

A span of objects to format.

Returns

true if the entire interpolated string could be formatted successfully; otherwise, false.

Exceptions

format is null.

The index of a format item is greater than or equal to the number of supplied arguments.

Applies to

.NET 9 and .NET 8
Product Versions
.NET 8, 9

TryWrite<TArg0,TArg1,TArg2>(Span<Char>, IFormatProvider, CompositeFormat, Int32, TArg0, TArg1, TArg2)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Writes the CompositeFormat string to the character span, substituting the format item or items with the string representation of the corresponding arguments.

public static bool TryWrite<TArg0,TArg1,TArg2> (this Span<char> destination, IFormatProvider? provider, System.Text.CompositeFormat format, out int charsWritten, TArg0 arg0, TArg1 arg1, TArg2 arg2);

Type Parameters

TArg0

The type of the first object to format.

TArg1

The type of the second object to format.

TArg2

The type of the third object to format.

Parameters

destination
Span<Char>

The span to which the string should be formatted.

provider
IFormatProvider

An object that supplies culture-specific formatting information.

charsWritten
Int32

When this method returns, contains the number of characters written to the span.

arg0
TArg0

The first object to format.

arg1
TArg1

The second object to format.

arg2
TArg2

The third object to format.

Returns

true if the entire interpolated string could be formatted successfully; otherwise, false.

Exceptions

format is null.

The index of a format item is greater than or equal to the number of supplied arguments.

Applies to

.NET 9 and .NET 8
Product Versions
.NET 8, 9

TryWrite<TArg0,TArg1>(Span<Char>, IFormatProvider, CompositeFormat, Int32, TArg0, TArg1)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Writes the CompositeFormat string to the character span, substituting the format item or items with the string representation of the corresponding arguments.

public static bool TryWrite<TArg0,TArg1> (this Span<char> destination, IFormatProvider? provider, System.Text.CompositeFormat format, out int charsWritten, TArg0 arg0, TArg1 arg1);

Type Parameters

TArg0

The type of the first object to format.

TArg1

The type of the second object to format.

Parameters

destination
Span<Char>

The span to which the string should be formatted.

provider
IFormatProvider

An object that supplies culture-specific formatting information.

charsWritten
Int32

When this method returns, contains the number of characters written to the span.

arg0
TArg0

The first object to format.

arg1
TArg1

The second object to format.

Returns

true if the entire interpolated string could be formatted successfully; otherwise, false.

Exceptions

format is null.

The index of a format item is greater than or equal to the number of supplied arguments.

Applies to

.NET 9 and .NET 8
Product Versions
.NET 8, 9

TryWrite<TArg0>(Span<Char>, IFormatProvider, CompositeFormat, Int32, TArg0)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Writes the CompositeFormat string to the character span, substituting the format item or items with the string representation of the corresponding arguments.

public static bool TryWrite<TArg0> (this Span<char> destination, IFormatProvider? provider, System.Text.CompositeFormat format, out int charsWritten, TArg0 arg0);

Type Parameters

TArg0

The type of the object to format.

Parameters

destination
Span<Char>

The span to which the string should be formatted.

provider
IFormatProvider

An object that supplies culture-specific formatting information.

charsWritten
Int32

When this method returns, contains the number of characters written to the span.

arg0
TArg0

The object to format.

Returns

true if the entire interpolated string could be formatted successfully; otherwise, false.

Exceptions

format is null.

The index of a format item is greater than or equal to the number of supplied arguments.

Applies to

.NET 9 and .NET 8
Product Versions
.NET 8, 9