SByte.ToString 方法  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将此实例的数值转换为其等效的字符串表示形式。
重载
| ToString() | 将此实例的数值转换为其等效的字符串表示形式。 | 
| ToString(IFormatProvider) | 使用指定的区域性特定格式信息,将此实例的数值转换为它的等效字符串表示形式。 | 
| ToString(String) | 使用指定的格式,将此实例的数值转换为它的等效字符串表示形式。 | 
| ToString(String, IFormatProvider) | 使用指定的格式和区域性特定格式信息,将此实例的数值转换为它的等效字符串表示形式。 | 
ToString()
- Source:
- SByte.cs
- Source:
- SByte.cs
- Source:
- SByte.cs
将此实例的数值转换为其等效的字符串表示形式。
public:
 override System::String ^ ToString();public override string ToString ();override this.ToString : unit -> stringPublic Overrides Function ToString () As String返回
此实例的值的字符串表示形式,由减号(如果值为负)和没有前导零的从 0 到 9 的数字序列组成。
示例
以下示例使用默认ToString()方法显示一个SByte值。 它还显示使用许多标准格式说明符产生的值的字符串表示形式 SByte 。 使用 en-US 区域性的格式设置约定显示示例。
using System;
public class Example
{
   public static void Main()
   {
      sbyte value = -123;
      // Display value using default ToString method.
      Console.WriteLine(value.ToString());            // Displays -123
      // Display value using some standard format specifiers.
      Console.WriteLine(value.ToString("G"));         // Displays -123
      Console.WriteLine(value.ToString("C"));         // Displays ($-123.00)
      Console.WriteLine(value.ToString("D"));         // Displays -123
      Console.WriteLine(value.ToString("F"));         // Displays -123.00
      Console.WriteLine(value.ToString("N"));         // Displays -123.00
      Console.WriteLine(value.ToString("X"));         // Displays 85
   }
}
let value = -123y
// Display value using default ToString method.
printfn $"{value.ToString()}"               // Displays -123
// Display value using some standard format specifiers.
printfn $"""{value.ToString "G"}"""         // Displays -123
printfn $"""{value.ToString "C"}"""         // Displays ($-123.00)
printfn $"""{value.ToString "D"}"""         // Displays -123
printfn $"""{value.ToString "F"}"""         // Displays -123.00
printfn $"""{value.ToString "N"}"""         // Displays -123.00
printfn $"""{value.ToString "X"}"""         // Displays 85
Module Example
   Public Sub Main()
      Dim value As SByte = -123
      ' Display value using default ToString method.
      Console.WriteLine(value.ToString())            ' Displays -123
      ' Display value using some standard format specifiers.
      Console.WriteLine(value.ToString("G"))         ' Displays -123
      Console.WriteLine(value.ToString("C"))         ' Displays ($-123.00)
      Console.WriteLine(value.ToString("D"))         ' Displays -123
      Console.WriteLine(value.ToString("F"))         ' Displays -123.00
      Console.WriteLine(value.ToString("N"))         ' Displays -123.00
      Console.WriteLine(value.ToString("X"))         ' Displays 85
   End Sub
End Module
注解
方法 ToString() 采用 SByte 默认 (“G”或当前区域性的常规) 格式设置值的格式。 如果要指定不同的格式或区域性,请使用 方法的其他重载 ToString ,如下所示:
| 使用格式 | 对于区域性 | 使用重载 | 
|---|---|---|
| 默认 (“G”) 格式 | 特定区域性 | ToString(IFormatProvider) | 
| 特定格式 | 默认 (当前) 区域性 | ToString(String) | 
| 特定格式 | 特定区域性 | ToString(String, IFormatProvider) | 
使用常规数值格式说明符 (“G”) 返回值的字符串表示形式 SByte 包括负号(如果值为负数),以及介于 0 到 9 的数字序列中没有前导零。 负号由 NumberFormatInfo 对象为当前区域性定义。
若要定义带符号字节值的字符串表示形式的格式,请调用 ToString(String) 方法。
另请参阅
适用于
ToString(IFormatProvider)
- Source:
- SByte.cs
- Source:
- SByte.cs
- Source:
- SByte.cs
使用指定的区域性特定格式信息,将此实例的数值转换为它的等效字符串表示形式。
public:
 virtual System::String ^ ToString(IFormatProvider ^ provider);public:
 System::String ^ ToString(IFormatProvider ^ provider);public string ToString (IFormatProvider provider);public string ToString (IFormatProvider? provider);override this.ToString : IFormatProvider -> stringPublic Function ToString (provider As IFormatProvider) As String参数
- provider
- IFormatProvider
一个提供区域性特定的格式设置信息的对象。
返回
此实例的值的字符串表示形式,由 provider 指定。
实现
示例
以下示例定义一个自定义 NumberFormatInfo 对象,并将“~”字符分配给其 NegativeSign 属性。 然后,该示例使用此自定义对象以及 NumberFormatInfo 固定区域性的对象来设置一系列值的格式 SByte 。
using System;
using System.Globalization;
public class Example
{
   public static void Main()
   {
      // Define a custom NumberFormatInfo object with "~" as its negative sign.
      NumberFormatInfo nfi = new NumberFormatInfo();
      nfi.NegativeSign = "~";
      
      // Initialize an array of SByte values.
      sbyte[] bytes = { -122, 17, 124 };
      // Display the formatted result using the custom provider.
      Console.WriteLine("Using the custom NumberFormatInfo object:");
      foreach (sbyte value in bytes)
         Console.WriteLine(value.ToString(nfi));
      Console.WriteLine();
          
      // Display the formatted result using the invariant culture.
      Console.WriteLine("Using the invariant culture:");
      foreach (sbyte value in bytes)
         Console.WriteLine(value.ToString(NumberFormatInfo.InvariantInfo));
   }
}
// The example displays the following output:
//       Using the custom NumberFormatInfo object:
//       ~122
//       17
//       124
//       
//       Using the invariant culture:
//       -122
//       17
//       124
open System.Globalization
// Define a custom NumberFormatInfo object with "~" as its negative sign.
let nfi = NumberFormatInfo(NegativeSign = "~")
// Initialize an array of SByte values.
let bytes = [| -122y; 17y; 124y |]
// Display the formatted result using the custom provider.
printfn "Using the custom NumberFormatInfo object:"
for value in bytes do
    printfn $"{value.ToString nfi}"
printfn ""
      
// Display the formatted result using the invariant culture.
printfn "Using the invariant culture:"
for value in bytes do
   printfn $"{value.ToString NumberFormatInfo.InvariantInfo}"
// The example displays the following output:
//       Using the custom NumberFormatInfo object:
//       ~122
//       17
//       124
//       
//       Using the invariant culture:
//       -122
//       17
//       124
Imports System.Globalization
Module Example
   Public Sub Main()
      ' Define a custom NumberFormatInfo object with "~" as its negative sign.
      Dim nfi As New NumberFormatInfo()
      nfi.NegativeSign = "~"
      
      ' Initialize an array of SByte values.
      Dim bytes() As SByte = { -122, 17, 124 }
      ' Display the formatted result using the custom provider.
      Console.WriteLine("Using the custom NumberFormatInfo object:")
      For Each value As SByte In bytes
         Console.WriteLine(value.ToString(nfi))
      Next
      Console.WriteLine()
          
      ' Display the formatted result using the invariant culture.
      Console.WriteLine("Using the invariant culture:")
      For Each value As SByte In bytes
         Console.WriteLine(value.ToString(NumberFormatInfo.InvariantInfo))
      Next   
   End Sub
End Module
' The example displays the following output:
'       Using the custom NumberFormatInfo object:
'       ~122
'       17
'       124
'       
'       Using the invariant culture:
'       -122
'       17
'       124
注解
方法 ToString(IFormatProvider) 采用 SByte 默认 (“G”或指定区域性的常规) 格式设置值的格式。 如果要指定其他格式或当前区域性,请使用 方法的其他重载 ToString ,如下所示:
| 使用格式 | 对于区域性 | 使用重载 | 
|---|---|---|
| 默认 (“G”) 格式 | 默认 (当前) 区域性 | ToString() | 
| 特定格式 | 默认 (当前) 区域性 | ToString(String) | 
| 特定格式 | 特定区域性 | ToString(String, IFormatProvider) | 
参数 provider 是实现 IFormatProvider 。 其 GetFormat 方法返回一个 NumberFormatInfo 对象,该对象提供有关此方法返回的字符串格式的区域性特定信息。 如果 provider 为 null,则 SByte 使用 NumberFormatInfo 当前区域性的 对象设置值的格式。 使用常规格式说明符控制值的字符串表示形式的 SByte 对象的唯一属性NumberFormatInfo是 NumberFormatInfo.NegativeSign,它定义表示负号的字符。
参数 provider 可以是以下参数之一:
- 一个 CultureInfo 对象,该对象表示提供格式设置信息的区域性。 
- NumberFormatInfo提供格式设置信息的 对象。 
- 实现 的 IFormatProvider自定义对象。 其 GetFormat 方法返回 NumberFormatInfo 提供格式设置信息的 对象。 
另请参阅
适用于
ToString(String)
- Source:
- SByte.cs
- Source:
- SByte.cs
- Source:
- SByte.cs
使用指定的格式,将此实例的数值转换为它的等效字符串表示形式。
public:
 System::String ^ ToString(System::String ^ format);public string ToString (string format);public string ToString (string? format);override this.ToString : string -> stringPublic Function ToString (format As String) As String参数
- format
- String
标准或自定义的数值格式字符串。
返回
此实例的值的字符串表示形式,由 format 指定。
例外
              format 无效。
示例
以下示例初始化值数组, SByte 并使用每个标准格式字符串和一些自定义格式字符串显示它们。
using System;
using System.Globalization;
public class Example
{
   public static void Main()
   {
      sbyte[] values = { -124, 0, 118 };
      string[] specifiers = { "G", "C", "D3", "E2", "e3", "F", 
                              "N", "P", "X", "00.0", "#.0", 
                              "000;(0);**Zero**" };
      
      foreach (sbyte value in values)
      {
         foreach (string specifier in specifiers)
            Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//       G: -124
//       C: ($124.00)
//       D3: -124
//       E2: -1.24E+002
//       e3: -1.240e+002
//       F: -124.00
//       N: -124.00
//       P: -12,400.00 %
//       X: 84
//       00.0: -124.0
//       #.0: -124.0
//       000;(0);**Zero**: (124)
//       
//       G: 0
//       C: $0.00
//       D3: 000
//       E2: 0.00E+000
//       e3: 0.000e+000
//       F: 0.00
//       N: 0.00
//       P: 0.00 %
//       X: 0
//       00.0: 00.0
//       #.0: .0
//       000;(0);**Zero**: **Zero**
//       
//       G: 118
//       C: $118.00
//       D3: 118
//       E2: 1.18E+002
//       e3: 1.180e+002
//       F: 118.00
//       N: 118.00
//       P: 11,800.00 %
//       X: 76
//       00.0: 118.0
//       #.0: 118.0
//       000;(0);**Zero**: 118
let values = [| -124y; 0y; 118y |]
let specifiers = 
    [| "G"; "C"; "D3"; "E2"; "e3"; "F" 
       "N"; "P"; "X"; "00.0"; "#.0" 
       "000(0)**Zero**" |]
for value in values do
    for specifier in specifiers do
        printfn $"{specifier}: {value.ToString specifier}"
    printfn ""
// The example displays the following output:
//       G: -124
//       C: ($124.00)
//       D3: -124
//       E2: -1.24E+002
//       e3: -1.240e+002
//       F: -124.00
//       N: -124.00
//       P: -12,400.00 %
//       X: 84
//       00.0: -124.0
//       #.0: -124.0
//       000(0)**Zero**: (124)
//       
//       G: 0
//       C: $0.00
//       D3: 000
//       E2: 0.00E+000
//       e3: 0.000e+000
//       F: 0.00
//       N: 0.00
//       P: 0.00 %
//       X: 0
//       00.0: 00.0
//       #.0: .0
//       000(0)**Zero**: **Zero**
//       
//       G: 118
//       C: $118.00
//       D3: 118
//       E2: 1.18E+002
//       e3: 1.180e+002
//       F: 118.00
//       N: 118.00
//       P: 11,800.00 %
//       X: 76
//       00.0: 118.0
//       #.0: 118.0
//       000(0)**Zero**: 118
Imports System.Globalization
Module Example
   Public Sub Main()
      Dim values() As SByte = { -124, 0, 118 }
      Dim specifiers() As String = { "G", "C", "D3", "E2", "e3", "F", _
                                     "N", "P", "X", "00.0", "#.0", _
                                     "000;(0);**Zero**" }
      
      For Each value As SByte In values
         For Each specifier As String In specifiers
            Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'       G: -124
'       C: ($124.00)
'       D3: -124
'       E2: -1.24E+002
'       e3: -1.240e+002
'       F: -124.00
'       N: -124.00
'       P: -12,400.00 %
'       X: 84
'       00.0: -124.0
'       #.0: -124.0
'       000;(0);**Zero**: (124)
'       
'       G: 0
'       C: $0.00
'       D3: 000
'       E2: 0.00E+000
'       e3: 0.000e+000
'       F: 0.00
'       N: 0.00
'       P: 0.00 %
'       X: 0
'       00.0: 00.0
'       #.0: .0
'       000;(0);**Zero**: **Zero**
'       
'       G: 118
'       C: $118.00
'       D3: 118
'       E2: 1.18E+002
'       e3: 1.180e+002
'       F: 118.00
'       N: 118.00
'       P: 11,800.00 %
'       X: 76
'       00.0: 118.0
'       #.0: 118.0
'       000;(0);**Zero**: 118
注解
方法ToString(String)SByte使用当前区域性的约定以指定格式设置值的格式。 如果要使用默认 (“G”或常规) 格式或指定其他区域性,请使用 方法的其他重载 ToString ,如下所示:
| 使用格式 | 对于区域性 | 使用重载 | 
|---|---|---|
| 默认 (“G”) 格式 | 默认 (当前) 区域性 | ToString() | 
| 默认 (“G”) 格式 | 特定区域性 | ToString(IFormatProvider) | 
| 特定格式 | 特定区域性 | ToString(String, IFormatProvider) | 
参数 format 可以是任何有效的标准数字格式说明符,也可以是自定义数值格式说明符的任意组合。 如果 format 等于 String.Empty 或 为 null,则使用常规格式说明符 (“G”) 格式化当前 SByte 对象的返回值。 如果 format 是任何其他值,则 方法将 FormatException引发 。
.NET 提供广泛的格式设置支持,以下格式设置主题对此进行了更详细的介绍:
- 有关数值格式说明符的详细信息,请参阅 标准数值格式字符串 和 自定义数值格式字符串。 
- 有关对 .NET 中格式设置的支持的详细信息,请参阅 格式设置类型。 
返回的字符串的格式由 NumberFormatInfo 当前区域性的 对象确定。 根据 format 参数,此对象控制输出字符串中的负号、组分隔符和小数点符号等符号。 若要为当前区域性以外的区域性提供格式设置信息,请调用 ToString(String, IFormatProvider) 重载。
另请参阅
适用于
ToString(String, IFormatProvider)
- Source:
- SByte.cs
- Source:
- SByte.cs
- Source:
- SByte.cs
使用指定的格式和区域性特定格式信息,将此实例的数值转换为它的等效字符串表示形式。
public:
 virtual System::String ^ ToString(System::String ^ format, IFormatProvider ^ provider);public string ToString (string format, IFormatProvider provider);public string ToString (string? format, IFormatProvider? provider);override this.ToString : string * IFormatProvider -> stringPublic Function ToString (format As String, provider As IFormatProvider) As String参数
- format
- String
标准或自定义的数值格式字符串。
- provider
- IFormatProvider
一个提供区域性特定的格式设置信息的对象。
返回
此实例的值的字符串表示形式,由 format 和 provider 指定。
实现
例外
              format 无效。
示例
以下示例使用标准数值格式说明符和多个特定CultureInfo对象显示正值和负SByte值。
using System;
using System.Globalization;
public class Example
{
   public static void Main()
   {
      // Define cultures whose formatting conventions are to be used.
      CultureInfo[] cultures = { CultureInfo.CreateSpecificCulture("en-US"), 
                                 CultureInfo.CreateSpecificCulture("fr-FR"), 
                                 CultureInfo.CreateSpecificCulture("es-ES") };
      sbyte positiveNumber = 119;
      sbyte negativeNumber = -45;
      string[] specifiers = {"G", "C", "D4", "E2", "F", "N", "P", "X2"}; 
      
      foreach (string specifier in specifiers)
      {
         foreach (CultureInfo culture in cultures)
            Console.WriteLine("{0,2} format using {1} culture: {2, 16} {3, 16}",  
                              specifier, culture.Name, 
                              positiveNumber.ToString(specifier, culture), 
                              negativeNumber.ToString(specifier, culture));
         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//     G format using en-US culture:              119              -45
//     G format using fr-FR culture:              119              -45
//     G format using es-ES culture:              119              -45
//    
//     C format using en-US culture:          $119.00         ($45.00)
//     C format using fr-FR culture:         119,00 €         -45,00 €
//     C format using es-ES culture:         119,00 €         -45,00 €
//    
//    D4 format using en-US culture:             0119            -0045
//    D4 format using fr-FR culture:             0119            -0045
//    D4 format using es-ES culture:             0119            -0045
//    
//    E2 format using en-US culture:        1.19E+002       -4.50E+001
//    E2 format using fr-FR culture:        1,19E+002       -4,50E+001
//    E2 format using es-ES culture:        1,19E+002       -4,50E+001
//    
//     F format using en-US culture:           119.00           -45.00
//     F format using fr-FR culture:           119,00           -45,00
//     F format using es-ES culture:           119,00           -45,00
//    
//     N format using en-US culture:           119.00           -45.00
//     N format using fr-FR culture:           119,00           -45,00
//     N format using es-ES culture:           119,00           -45,00
//    
//     P format using en-US culture:      11,900.00 %      -4,500.00 %
//     P format using fr-FR culture:      11 900,00 %      -4 500,00 %
//     P format using es-ES culture:      11.900,00 %      -4.500,00 %
//    
//    X2 format using en-US culture:               77               D3
//    X2 format using fr-FR culture:               77               D3
//    X2 format using es-ES culture:               77               D3
open System.Globalization
// Define cultures whose formatting conventions are to be used.
let cultures = 
    [| CultureInfo.CreateSpecificCulture "en-US" 
       CultureInfo.CreateSpecificCulture "fr-FR" 
       CultureInfo.CreateSpecificCulture "es-ES" |]
let positiveNumber = 119y
let negativeNumber = -45y
let specifiers = [| "G"; "C"; "D4"; "E2"; "F"; "N"; "P"; "X2" |]
for specifier in specifiers do
    for culture in cultures do
        printfn $"{specifier,2} format using {culture.Name} culture: {positiveNumber.ToString(specifier, culture), 16} {negativeNumber.ToString(specifier, culture), 16}"
    printfn ""
// The example displays the following output:
//     G format using en-US culture:              119              -45
//     G format using fr-FR culture:              119              -45
//     G format using es-ES culture:              119              -45
//    
//     C format using en-US culture:          $119.00         ($45.00)
//     C format using fr-FR culture:         119,00 €         -45,00 €
//     C format using es-ES culture:         119,00 €         -45,00 €
//    
//    D4 format using en-US culture:             0119            -0045
//    D4 format using fr-FR culture:             0119            -0045
//    D4 format using es-ES culture:             0119            -0045
//    
//    E2 format using en-US culture:        1.19E+002       -4.50E+001
//    E2 format using fr-FR culture:        1,19E+002       -4,50E+001
//    E2 format using es-ES culture:        1,19E+002       -4,50E+001
//    
//     F format using en-US culture:           119.00           -45.00
//     F format using fr-FR culture:           119,00           -45,00
//     F format using es-ES culture:           119,00           -45,00
//    
//     N format using en-US culture:           119.00           -45.00
//     N format using fr-FR culture:           119,00           -45,00
//     N format using es-ES culture:           119,00           -45,00
//    
//     P format using en-US culture:      11,900.00 %      -4,500.00 %
//     P format using fr-FR culture:      11 900,00 %      -4 500,00 %
//     P format using es-ES culture:      11.900,00 %      -4.500,00 %
//    
//    X2 format using en-US culture:               77               D3
//    X2 format using fr-FR culture:               77               D3
//    X2 format using es-ES culture:               77               D3
Imports System.Globalization
Module Example
   Public Sub Main()
      ' Define cultures whose formatting conventions are to be used.
      Dim cultures() As CultureInfo = {CultureInfo.CreateSpecificCulture("en-US"), _
                                       CultureInfo.CreateSpecificCulture("fr-FR"), _
                                       CultureInfo.CreateSpecificCulture("es-ES") }
      Dim positiveNumber As SByte = 119
      Dim negativeNumber As SByte = -45
      Dim specifiers() As String = {"G", "C", "D4", "E2", "F", "N", "P", "X2"} 
      
      For Each specifier As String In specifiers
         For Each culture As CultureInfo In Cultures
            Console.WriteLine("{0,2} format using {1} culture: {2, 16} {3, 16}", _ 
                              specifier, culture.Name, _
                              positiveNumber.ToString(specifier, culture), _
                              negativeNumber.ToString(specifier, culture))
         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'     G format using en-US culture:              119              -45
'     G format using fr-FR culture:              119              -45
'     G format using es-ES culture:              119              -45
'    
'     C format using en-US culture:          $119.00         ($45.00)
'     C format using fr-FR culture:         119,00 €         -45,00 €
'     C format using es-ES culture:         119,00 €         -45,00 €
'    
'    D4 format using en-US culture:             0119            -0045
'    D4 format using fr-FR culture:             0119            -0045
'    D4 format using es-ES culture:             0119            -0045
'    
'    E2 format using en-US culture:        1.19E+002       -4.50E+001
'    E2 format using fr-FR culture:        1,19E+002       -4,50E+001
'    E2 format using es-ES culture:        1,19E+002       -4,50E+001
'    
'     F format using en-US culture:           119.00           -45.00
'     F format using fr-FR culture:           119,00           -45,00
'     F format using es-ES culture:           119,00           -45,00
'    
'     N format using en-US culture:           119.00           -45.00
'     N format using fr-FR culture:           119,00           -45,00
'     N format using es-ES culture:           119,00           -45,00
'    
'     P format using en-US culture:      11,900.00 %      -4,500.00 %
'     P format using fr-FR culture:      11 900,00 %      -4 500,00 %
'     P format using es-ES culture:      11.900,00 %      -4.500,00 %
'    
'    X2 format using en-US culture:               77               D3
'    X2 format using fr-FR culture:               77               D3
'    X2 format using es-ES culture:               77               D3
注解
方法 ToString(String, IFormatProvider) 以 SByte 指定区域性的指定格式设置值的格式。 如果要使用默认格式或区域性设置,请使用 方法的其他重载 ToString ,如下所示:
| 使用格式 | 对于区域性 | 使用重载 | 
|---|---|---|
| 默认 (“G”) 格式 | 默认 (当前) 区域性 | ToString() | 
| 默认 (“G”) 格式 | 特定区域性 | ToString(IFormatProvider) | 
| 特定格式 | 默认 (当前) 区域性 | ToString(String) | 
参数 format 可以是任何有效的标准数字格式说明符,也可以是自定义数字格式说明符的任意组合。 如果 format 等于 String.Empty 或 为 null,则使用常规格式说明符 (“G”) 设置当前 SByte 对象的返回值的格式。 如果 format 是任何其他值,该方法将 FormatException引发 。
.NET 提供广泛的格式设置支持,以下格式设置主题对此进行了更详细的介绍:
- 有关数字格式说明符的详细信息,请参阅 标准数字格式字符串 和 自定义数值格式字符串。 
- 有关 .NET 中对格式设置的支持的详细信息,请参阅 格式设置类型。 
参数 provider 是实现 IFormatProvider 。 其 GetFormat 方法返回一个 NumberFormatInfo 对象,该对象提供有关此方法返回的字符串格式的区域性特定信息。 
              ToString(String, IFormatProvider)调用 方法时,它会调用provider参数的 IFormatProvider.GetFormat 方法,并向其传递表示Type类型的 NumberFormatInfo 对象。 然后, GetFormat 方法返回 NumberFormatInfo 对象,该对象提供设置参数格式 value 的信息,例如负号符号、组分隔符符号或小数点符号。 有三种方法可以使用 provider 参数向 方法提供格式设置信息 ToString(String, IFormatProvider) :
- 可以传递一个 CultureInfo 对象,该对象表示提供格式设置信息的区域性。 其 GetFormat 方法返回对象, NumberFormatInfo 该对象提供该区域性的数字格式设置信息。 
- 可以传递提供数字格式设置信息的实际 NumberFormatInfo 对象。 (它的 实现 GetFormat 只返回自身。) 
- 可以传递实现 的 IFormatProvider自定义对象。 其 GetFormat 方法实例化并返回 NumberFormatInfo 提供格式设置信息的 对象。 
如果 provider 为 null,则返回的字符串的格式基于 NumberFormatInfo 当前区域性的 对象。
另请参阅
- 设置 .NET 中类型的格式
- 如何:用前导零填充数字
- 标准数字格式字符串
- 自定义数字格式字符串
- 示例:.NET Core WinForms 格式设置实用工具 (C#)
- 示例:.NET Core WinForms 格式设置实用工具 (Visual Basic)