MemoryExtensions.TryWrite 方法

定义

重载

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

CompositeFormat 字符串写入字符范围,用相应参数的字符串表示形式替换格式项或项。

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

将指定的内插字符串写入字符范围。

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

将指定的内插字符串写入字符范围。

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

CompositeFormat 字符串写入字符范围,用相应参数的字符串表示形式替换格式项或项。

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

CompositeFormat 字符串写入字符范围,用相应参数的字符串表示形式替换格式项或项。

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

CompositeFormat 字符串写入字符范围,用相应参数的字符串表示形式替换格式项或项。

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

CompositeFormat 字符串写入字符范围,用相应参数的字符串表示形式替换格式项或项。

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

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

CompositeFormat 字符串写入字符范围,用相应参数的字符串表示形式替换格式项或项。

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

参数

destination
Span<Char>

应设置字符串格式的跨度。

provider
IFormatProvider

提供区域性特定的格式设置信息的对象。

charsWritten
Int32

此方法返回时,包含写入到范围中的字符数。

args
Object[]

要设置格式的对象数组。

返回

如果成功格式化整个内插字符串,则 true;否则,false

例外

formatargsnull

格式项的索引大于或等于提供的参数数。

适用于

.NET 9 和 .NET 8
产品 版本
.NET 8, 9

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

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

将指定的内插字符串写入字符范围。

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

参数

destination
Span<Char>

应设置内插字符串格式的跨度。

handler
MemoryExtensions.TryWriteInterpolatedStringHandler

内插字符串,由引用传递。

charsWritten
Int32

此方法返回时,包含写入到范围中的字符数。

返回

如果成功格式化整个内插字符串,则 true;否则,false

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9

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

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

将指定的内插字符串写入字符范围。

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

参数

destination
Span<Char>

应设置内插字符串格式的跨度。

provider
IFormatProvider

提供区域性特定的格式设置信息的对象。

handler
MemoryExtensions.TryWriteInterpolatedStringHandler

内插字符串,由引用传递。

charsWritten
Int32

此方法返回时,包含写入到范围中的字符数。

返回

如果成功格式化整个内插字符串,则 true;否则,false

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9

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

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

CompositeFormat 字符串写入字符范围,用相应参数的字符串表示形式替换格式项或项。

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);

参数

destination
Span<Char>

应设置字符串格式的跨度。

provider
IFormatProvider

提供区域性特定的格式设置信息的对象。

charsWritten
Int32

此方法返回时,包含写入到范围中的字符数。

args
ReadOnlySpan<Object>

要设置格式的对象范围。

返回

如果成功格式化整个内插字符串,则 true;否则,false

例外

format null

格式项的索引大于或等于提供的参数数。

适用于

.NET 9 和 .NET 8
产品 版本
.NET 8, 9

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

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

CompositeFormat 字符串写入字符范围,用相应参数的字符串表示形式替换格式项或项。

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);

类型参数

TArg0

要设置格式的第一个对象的类型。

TArg1

要设置格式的第二个对象的类型。

TArg2

要设置格式的第三个对象的类型。

参数

destination
Span<Char>

应设置字符串格式的跨度。

provider
IFormatProvider

提供区域性特定的格式设置信息的对象。

charsWritten
Int32

此方法返回时,包含写入到范围中的字符数。

arg0
TArg0

要设置格式的第一个对象。

arg1
TArg1

要设置格式的第二个对象。

arg2
TArg2

要设置格式的第三个对象。

返回

如果成功格式化整个内插字符串,则 true;否则,false

例外

format null

格式项的索引大于或等于提供的参数数。

适用于

.NET 9 和 .NET 8
产品 版本
.NET 8, 9

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

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

CompositeFormat 字符串写入字符范围,用相应参数的字符串表示形式替换格式项或项。

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

类型参数

TArg0

要设置格式的第一个对象的类型。

TArg1

要设置格式的第二个对象的类型。

参数

destination
Span<Char>

应设置字符串格式的跨度。

provider
IFormatProvider

提供区域性特定的格式设置信息的对象。

charsWritten
Int32

此方法返回时,包含写入到范围中的字符数。

arg0
TArg0

要设置格式的第一个对象。

arg1
TArg1

要设置格式的第二个对象。

返回

如果成功格式化整个内插字符串,则 true;否则,false

例外

format null

格式项的索引大于或等于提供的参数数。

适用于

.NET 9 和 .NET 8
产品 版本
.NET 8, 9

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

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

CompositeFormat 字符串写入字符范围,用相应参数的字符串表示形式替换格式项或项。

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

类型参数

TArg0

要设置格式的对象的类型。

参数

destination
Span<Char>

应设置字符串格式的跨度。

provider
IFormatProvider

提供区域性特定的格式设置信息的对象。

charsWritten
Int32

此方法返回时,包含写入到范围中的字符数。

arg0
TArg0

要设置格式的对象。

返回

如果成功格式化整个内插字符串,则 true;否则,false

例外

format null

格式项的索引大于或等于提供的参数数。

适用于

.NET 9 和 .NET 8
产品 版本
.NET 8, 9