SByte.ToString Metodo

Definizione

Converte il valore numerico dell'istanza nella rappresentazione di stringa equivalente.

Overload

ToString()

Converte il valore numerico dell'istanza nella rappresentazione di stringa equivalente.

ToString(IFormatProvider)

Converte il valore numerico di questa istanza nella rappresentazione di stringa equivalente usando le informazioni di formato specifiche delle impostazioni cultura.

ToString(String)

Converte il valore numerico di questa istanza nell'equivalente rappresentazione di stringa usando il formato specificato.

ToString(String, IFormatProvider)

Converte il valore numerico dell'istanza nella rappresentazione di stringa equivalente usando il formato specificato e le informazioni di formattazione specifiche delle impostazioni cultura.

ToString()

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

Converte il valore numerico dell'istanza nella rappresentazione di stringa equivalente.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

Restituisce

Rappresentazione di stringa del valore dell'istanza, composta da un segno negativo (se il valore è negativo) e una sequenza di cifre comprese tra 0 e 9 senza zeri iniziali.

Esempio

Nell'esempio seguente viene visualizzato un SByte valore usando il metodo predefinito ToString() . Vengono inoltre visualizzate le rappresentazioni di stringa del SByte valore risultante dall'uso di un numero di identificatori di formato standard. Gli esempi vengono visualizzati usando le convenzioni di formattazione delle impostazioni cultura 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

Commenti

Il ToString() metodo formatta un SByte valore nel formato predefinito ("G" o generale) delle impostazioni cultura correnti. Se si desidera specificare un formato o impostazioni cultura diverse, usare gli altri overload del ToString metodo, come indicato di seguito:

Per usare il formato Per le impostazioni cultura Usare l'overload
Formato predefinito ("G") Impostazioni cultura specifiche ToString(IFormatProvider)
Un formato specifico Impostazioni cultura predefinite (correnti) ToString(String)
Un formato specifico Impostazioni cultura specifiche ToString(String, IFormatProvider)

Il valore restituito viene formattato usando l'identificatore di formato numerico generale ("G") La rappresentazione di stringa del SByte valore include un segno negativo se il valore è negativo e una sequenza di cifre compresa tra 0 e 9 senza zeri iniziali. Il segno negativo è definito dall'oggetto NumberFormatInfo per le impostazioni cultura correnti.

Per definire la formattazione della rappresentazione di stringa del valore di byte firmato, chiamare il ToString(String) metodo .

Vedi anche

Si applica a

ToString(IFormatProvider)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

Converte il valore numerico di questa istanza nella rappresentazione di stringa equivalente usando le informazioni di formato specifiche delle impostazioni cultura.

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 -> string
Public Function ToString (provider As IFormatProvider) As String

Parametri

provider
IFormatProvider

Oggetto che fornisce informazioni di formattazione specifiche delle impostazioni cultura.

Restituisce

Rappresentazione di stringa del valore dell'istanza, in base a quanto specificato da provider.

Implementazioni

Esempio

Nell'esempio seguente viene definito un oggetto personalizzato NumberFormatInfo e viene assegnato il carattere "~" alla relativa NegativeSign proprietà. Nell'esempio viene quindi utilizzato questo oggetto personalizzato e l'oggetto NumberFormatInfo delle impostazioni cultura invarianti per formattare una serie di SByte valori.

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

Commenti

Il ToString(IFormatProvider) metodo formatta un SByte valore nel formato predefinito ("G" o generale) di impostazioni cultura specificate. Se si desidera specificare un formato diverso o le impostazioni cultura correnti, usare gli altri overload del ToString metodo, come indicato di seguito:

Per usare il formato Per le impostazioni cultura Usare l'overload
Formato predefinito ("G") Impostazioni cultura predefinite (correnti) ToString()
Un formato specifico Impostazioni cultura predefinite (correnti) ToString(String)
Un formato specifico Impostazioni cultura specifiche ToString(String, IFormatProvider)

Il provider parametro è un'implementazione IFormatProvider . Il metodo GetFormat restituisce un NumberFormatInfo oggetto che fornisce informazioni specifiche delle impostazioni cultura sul formato della stringa restituita da questo metodo. Se provider è null, il SByte valore viene formattato utilizzando l'oggetto NumberFormatInfo delle impostazioni cultura correnti. L'unica proprietà dell'oggetto NumberFormatInfo che controlla la rappresentazione di stringa del SByte valore usando l'identificatore di formato generale è NumberFormatInfo.NegativeSign, che definisce il carattere che rappresenta il segno negativo.

Il provider parametro può essere uno dei seguenti:

Vedi anche

Si applica a

ToString(String)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

Converte il valore numerico di questa istanza nell'equivalente rappresentazione di stringa usando il formato specificato.

public:
 System::String ^ ToString(System::String ^ format);
public string ToString (string format);
public string ToString (string? format);
override this.ToString : string -> string
Public Function ToString (format As String) As String

Parametri

format
String

Stringa di formato numerico standard o personalizzato.

Restituisce

Rappresentazione di stringa del valore dell'istanza, in base a quanto specificato da format.

Eccezioni

format non è valido.

Esempio

Nell'esempio seguente viene inizializzata una matrice di valori e vengono visualizzati usando ogni stringa di SByte formato standard e alcune stringhe di formato personalizzate.

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

Commenti

Il ToString(String) metodo formatta un SByte valore in un formato specificato usando le convenzioni delle impostazioni cultura correnti. Se si desidera usare il formato predefinito ("G" o generale) o specificare impostazioni cultura diverse, usare gli altri overload del ToString metodo, come indicato di seguito:

Per usare il formato Per le impostazioni cultura Usare l'overload
Formato predefinito ("G") Impostazioni cultura predefinite (correnti) ToString()
Formato predefinito ("G") Impostazioni cultura specifiche ToString(IFormatProvider)
Un formato specifico Impostazioni cultura specifiche ToString(String, IFormatProvider)

Il format parametro può essere qualsiasi identificatore di formato numerico standard valido o qualsiasi combinazione di identificatori di formato numerico personalizzato. Se format è uguale a String.Empty o è null, il valore restituito dell'oggetto corrente SByte viene formattato con l'identificatore di formato generale ("G"). Se format è un altro valore, il metodo genera un oggetto FormatException.

.NET offre un supporto completo per la formattazione, descritto in modo più dettagliato negli argomenti di formattazione seguenti:

Il formato della stringa restituita è determinato dall'oggetto NumberFormatInfo per le impostazioni cultura correnti. A seconda del format parametro, questo oggetto controlla i simboli, ad esempio il segno negativo, il separatore di gruppo e il simbolo di virgola decimale nella stringa di output. Per fornire informazioni di formattazione per impostazioni cultura diverse dalle impostazioni cultura correnti, chiamare l'overload ToString(String, IFormatProvider) .

Vedi anche

Si applica a

ToString(String, IFormatProvider)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

Converte il valore numerico dell'istanza nella rappresentazione di stringa equivalente usando il formato specificato e le informazioni di formattazione specifiche delle impostazioni cultura.

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 -> string
Public Function ToString (format As String, provider As IFormatProvider) As String

Parametri

format
String

Stringa di formato numerico standard o personalizzato.

provider
IFormatProvider

Oggetto che fornisce informazioni di formattazione specifiche delle impostazioni cultura.

Restituisce

Rappresentazione di stringa del valore dell'istanza corrente, in base a quanto specificato da format e provider.

Implementazioni

Eccezioni

format non è valido.

Esempio

Nell'esempio seguente vengono visualizzati sia un valore positivo che un valore negativo SByte usando gli identificatori di formato numerico standard e un numero di oggetti specifici CultureInfo .

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

Commenti

Il ToString(String, IFormatProvider) metodo formatta un SByte valore in un formato specificato di impostazioni cultura specificate. Se si desidera usare le impostazioni di formato o impostazioni cultura predefinite, usare gli altri overload del ToString metodo, come indicato di seguito:

Per usare il formato Per le impostazioni cultura Usare l'overload
Formato predefinito ("G") Impostazioni cultura predefinite (correnti) ToString()
Formato predefinito ("G") Impostazioni cultura specifiche ToString(IFormatProvider)
Un formato specifico Impostazioni cultura predefinite (correnti) ToString(String)

Il format parametro può essere qualsiasi identificatore di formato numerico standard valido o qualsiasi combinazione di identificatori di formato numerico personalizzato. Se format è uguale a String.Empty o è null, il valore restituito dell'oggetto corrente SByte viene formattato con l'identificatore di formato generale ("G"). Se format è un altro valore, il metodo genera un oggetto FormatException.

.NET offre un supporto completo per la formattazione, descritto in modo più dettagliato negli argomenti di formattazione seguenti:

Il provider parametro è un'implementazione IFormatProvider . Il metodo GetFormat restituisce un NumberFormatInfo oggetto che fornisce informazioni specifiche delle impostazioni cultura sul formato della stringa restituita da questo metodo. Quando il ToString(String, IFormatProvider) metodo viene richiamato, chiama il provider metodo del IFormatProvider.GetFormat parametro e lo passa a un Type oggetto che rappresenta il NumberFormatInfo tipo. Il GetFormat metodo restituisce quindi l'oggetto NumberFormatInfo che fornisce informazioni per la formattazione del value parametro, ad esempio il simbolo del segno negativo, il simbolo separatore di gruppo o il simbolo di virgola decimale. Esistono tre modi per usare il provider parametro per fornire informazioni di formattazione al ToString(String, IFormatProvider) metodo :

  • È possibile passare un CultureInfo oggetto che rappresenta le impostazioni cultura che forniscono informazioni di formattazione. Il metodo GetFormat restituisce l'oggetto NumberFormatInfo che fornisce informazioni sulla formattazione numerica per tali impostazioni cultura.

  • È possibile passare l'oggetto effettivo NumberFormatInfo che fornisce informazioni sulla formattazione numerica. L'implementazione di GetFormat just restituisce se stessa.

  • È possibile passare un oggetto personalizzato che implementa IFormatProvider. Il GetFormat metodo crea un'istanza e restituisce l'oggetto NumberFormatInfo che fornisce informazioni di formattazione.

Se provider è null, la formattazione della stringa restituita è basata sull'oggetto NumberFormatInfo delle impostazioni cultura correnti.

Vedi anche

Si applica a