语言

Utf8Formatter.TryFormat 方法

定义

重载

名称 说明
TryFormat(Boolean, Span<Byte>, Int32, StandardFormat)

将 A Boolean 格式设置为 UTF8 字符串。

TryFormat(Byte, Span<Byte>, Int32, StandardFormat)

将 A Byte 格式设置为 UTF8 字符串。

TryFormat(DateTime, Span<Byte>, Int32, StandardFormat)

将 A DateTime 格式设置为 UTF8 字符串。

TryFormat(DateTimeOffset, Span<Byte>, Int32, StandardFormat)

将 A DateTimeOffset 格式设置为 UTF8 字符串。

TryFormat(Decimal, Span<Byte>, Int32, StandardFormat)

将 A Decimal 格式设置为 UTF8 字符串。

TryFormat(Double, Span<Byte>, Int32, StandardFormat)

将 A Double 格式设置为 UTF8 字符串。

TryFormat(Guid, Span<Byte>, Int32, StandardFormat)

将 A Guid 格式设置为 UTF8 字符串。

TryFormat(Int16, Span<Byte>, Int32, StandardFormat)

将 UTF8 Int16 字符串的格式设置为 UTF8 字符串。

TryFormat(Int32, Span<Byte>, Int32, StandardFormat)

将 UTF8 Int32 字符串的格式设置为 UTF8 字符串。

TryFormat(Int64, Span<Byte>, Int32, StandardFormat)

将 UTF8 Int64 字符串的格式设置为 UTF8 字符串。

TryFormat(SByte, Span<Byte>, Int32, StandardFormat)

将 UTF8 SByte 字符串的格式设置为 UTF8 字符串。

TryFormat(Single, Span<Byte>, Int32, StandardFormat)

将 A Single 格式设置为 UTF8 字符串。

TryFormat(TimeSpan, Span<Byte>, Int32, StandardFormat)

将 A TimeSpan 格式设置为 UTF8 字符串。

TryFormat(UInt16, Span<Byte>, Int32, StandardFormat)

将 A UInt16 格式设置为 UTF8 字符串。

TryFormat(UInt32, Span<Byte>, Int32, StandardFormat)

将 A UInt32 格式设置为 UTF8 字符串。

TryFormat(UInt64, Span<Byte>, Int32, StandardFormat)

将 A UInt64 格式设置为 UTF8 字符串。

TryFormat(Boolean, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Boolean.cs
Source:
Utf8Formatter.Boolean.cs
Source:
Utf8Formatter.Boolean.cs
Source:
Utf8Formatter.Boolean.cs
Source:
Utf8Formatter.Boolean.cs

将 A Boolean 格式设置为 UTF8 字符串。

public static bool TryFormat(bool value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : bool * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Boolean, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
Boolean

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

注解

支持的格式:

格式字符串 示例结果字符串
G (默认值) 真/假
l 真/假

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(Byte, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

将 A Byte 格式设置为 UTF8 字符串。

public static bool TryFormat(byte value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : byte * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Byte, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
Byte

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

注解

支持的格式:

格式字符串 示例结果字符串
G/g (默认值)
D/d 122
N/n 122
X/x 7a

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(DateTime, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs

将 A DateTime 格式设置为 UTF8 字符串。

public static bool TryFormat(DateTime value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : DateTime * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As DateTime, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
DateTime

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

注解

支持的格式:

格式字符串 示例结果字符串 注释
G (默认值) 05/25/2017 10:30:15
R 2017年1月3日星期二 08:08:05 GMT (RFC 1123)
l 周二, 2017 年 1 月 3 日 08:08:05 gmt (小写 RFC 1123)
O 2017-06-12T05:30:45.7680000-07:00 (往返)

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(DateTimeOffset, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs

将 A DateTimeOffset 格式设置为 UTF8 字符串。

public static bool TryFormat(DateTimeOffset value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : DateTimeOffset * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As DateTimeOffset, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
DateTimeOffset

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

适用于

TryFormat(Decimal, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Decimal.cs
Source:
Utf8Formatter.Decimal.cs
Source:
Utf8Formatter.Decimal.cs
Source:
Utf8Formatter.Decimal.cs
Source:
Utf8Formatter.Decimal.cs

将 A Decimal 格式设置为 UTF8 字符串。

public static bool TryFormat(decimal value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : decimal * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Decimal, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
Decimal

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

注解

支持的格式:

格式字符串 示例结果字符串 注释
G/g (默认值)
F/f 12.45 固定点
E/e 1.245000e1 指数

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(Double, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs

将 A Double 格式设置为 UTF8 字符串。

public static bool TryFormat(double value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : double * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Double, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
Double

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

注解

支持的格式:

格式字符串 示例结果字符串 注释
G/g (默认值)
F/f 12.45 固定点
E/e 1.245000e1 指数

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(Guid, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Guid.cs
Source:
Utf8Formatter.Guid.cs
Source:
Utf8Formatter.Guid.cs
Source:
Utf8Formatter.Guid.cs
Source:
Utf8Formatter.Guid.cs

将 A Guid 格式设置为 UTF8 字符串。

public static bool TryFormat(Guid value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : Guid * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Guid, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
Guid

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

注解

支持的格式:

格式字符串 结果字符串
D (默认值) nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnn
B {nnnnnnnn-nnnn-nnnn-nnnn-nnnn}
P (nnnnnnnn-nnnn-nnnn-nnnn-nnnn)
N nnnn

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(Int16, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

将 UTF8 Int16 字符串的格式设置为 UTF8 字符串。

public static bool TryFormat(short value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : int16 * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Short, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
Int16

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

注解

支持的格式:

格式字符串 示例结果字符串
G/g (默认值)
D/d 32767
N/n 32,767
X/x 7fff

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(Int32, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

将 UTF8 Int32 字符串的格式设置为 UTF8 字符串。

public static bool TryFormat(int value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : int * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Integer, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
Int32

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

注解

支持的格式:

格式字符串 示例结果字符串
G/g (默认值)
D/d 32767
N/n 32,767
X/x 7fff

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(Int64, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

将 UTF8 Int64 字符串的格式设置为 UTF8 字符串。

public static bool TryFormat(long value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : int64 * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Long, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
Int64

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

注解

支持的格式:

格式字符串 示例结果字符串
G/g (默认值)
D/d 32767
N/n 32,767
X/x 7fff

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(SByte, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

重要

此 API 不符合 CLS。

将 UTF8 SByte 字符串的格式设置为 UTF8 字符串。

[System.CLSCompliant(false)]
public static bool TryFormat(sbyte value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
[<System.CLSCompliant(false)>]
static member TryFormat : sbyte * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As SByte, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
SByte

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

特性

注解

支持的格式:

格式字符串 示例结果字符串
G/g (默认值)
D/d 122
N/n 122
X/x 7a

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(Single, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs

将 A Single 格式设置为 UTF8 字符串。

public static bool TryFormat(float value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : single * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Single, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
Single

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

注解

支持的格式:

格式字符串 示例结果字符串 注释
G/g (默认值)
F/f 12.45 固定点
E/e 1.245000e1 指数

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(TimeSpan, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.TimeSpan.cs
Source:
Utf8Formatter.TimeSpan.cs
Source:
Utf8Formatter.TimeSpan.cs
Source:
Utf8Formatter.TimeSpan.cs
Source:
Utf8Formatter.TimeSpan.cs

将 A TimeSpan 格式设置为 UTF8 字符串。

public static bool TryFormat(TimeSpan value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : TimeSpan * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As TimeSpan, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
TimeSpan

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

注解

支持的格式:

格式字符串 结果字符串 注释
c/t/T (默认值) [-][d.]hh:mm:ss[.fffffff] (常量格式)
G [-]d:hh:mm:ss.fffffff (一般长)
克 [-][d:][h]h:mm:ss[.f[f[f[f[f[f[f[f]]]]]] (一般短)

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(UInt16, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

重要

此 API 不符合 CLS。

将 A UInt16 格式设置为 UTF8 字符串。

[System.CLSCompliant(false)]
public static bool TryFormat(ushort value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
[<System.CLSCompliant(false)>]
static member TryFormat : uint16 * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As UShort, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
UInt16

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

特性

注解

支持的格式:

格式字符串 示例结果字符串
G/g (默认值)
D/d 32767
N/n 32,767
X/x 7fff

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(UInt32, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

重要

此 API 不符合 CLS。

将 A UInt32 格式设置为 UTF8 字符串。

[System.CLSCompliant(false)]
public static bool TryFormat(uint value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
[<System.CLSCompliant(false)>]
static member TryFormat : uint32 * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As UInteger, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
UInt32

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

特性

注解

支持的格式:

格式字符串 示例结果字符串
G/g (默认值)
D/d 32767
N/n 32,767
X/x 7fff

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于

TryFormat(UInt64, Span<Byte>, Int32, StandardFormat)

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

重要

此 API 不符合 CLS。

将 A UInt64 格式设置为 UTF8 字符串。

[System.CLSCompliant(false)]
public static bool TryFormat(ulong value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
[<System.CLSCompliant(false)>]
static member TryFormat : uint64 * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As ULong, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

参数

value
UInt64

要格式化的值。

destination
Span<Byte>

要向其写入 UTF8 格式值的缓冲区。

bytesWritten
Int32

此方法返回时,包含格式化文本的长度(以字节为单位)。

format
StandardFormat

要使用的标准格式。

返回

true 如果格式设置操作成功,则为 false 如果 destination 太小,

特性

注解

支持的格式:

格式字符串 示例结果字符串
G/g (默认值)
D/d 32767
N/n 32,767
X/x 7fff

如果方法失败,请迭代增加缓冲区的大小,然后重试,直到成功。

适用于