Byte.ToString Metodo

Definizione

Converte il valore dell'oggetto Byte corrente nella rappresentazione di stringa equivalente.

Overload

ToString(IFormatProvider)

Converte il valore numerico dell'oggetto Byte corrente nella rappresentazione di stringa equivalente, usando le informazioni specificate relative alla formattazione delle impostazioni cultura.

ToString(String)

Converte il valore dell'oggetto Byte corrente nella rappresentazione di stringa equivalente, usando il formato specificato.

ToString(String, IFormatProvider)

Converte il valore dell'oggetto Byte corrente nella rappresentazione di stringa equivalente, usando il formato specificato e le informazioni di formattazione specifiche delle impostazioni cultura.

ToString()

Converte il valore dell'oggetto Byte corrente nella rappresentazione di stringa equivalente.

ToString(IFormatProvider)

Source:
Byte.cs
Source:
Byte.cs
Source:
Byte.cs

Converte il valore numerico dell'oggetto Byte corrente nella rappresentazione di stringa equivalente, usando le informazioni specificate relative alla formattazione 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 di questo oggetto nel formato specificato dal parametro provider.

Implementazioni

Esempio

L'esempio seguente esegue l'iterazione di una matrice di valori di byte e li visualizza nella console chiamando il ToString(IFormatProvider) metodo con provider di formato diversi.

array<Byte>^ bytes = gcnew array<Byte> {0, 1, 14, 168, 255};
array<CultureInfo^>^ providers = {gcnew CultureInfo("en-us"), 
                                  gcnew CultureInfo("fr-fr"), 
                                  gcnew CultureInfo("de-de"), 
                                  gcnew CultureInfo("es-es")};
for each (Byte byteValue in bytes)
{
   for each (CultureInfo^ provider in providers)
      Console::Write("{0,3} ({1})      ", 
                    byteValue.ToString(provider), provider->Name);

   Console::WriteLine();                                        
}
// The example displays the following output to the console:
//      0 (en-US)        0 (fr-FR)        0 (de-DE)        0 (es-ES)
//      1 (en-US)        1 (fr-FR)        1 (de-DE)        1 (es-ES)
//     14 (en-US)       14 (fr-FR)       14 (de-DE)       14 (es-ES)
//    168 (en-US)      168 (fr-FR)      168 (de-DE)      168 (es-ES)
//    255 (en-US)      255 (fr-FR)      255 (de-DE)      255 (es-ES)
byte[] bytes = {0, 1, 14, 168, 255};
CultureInfo[] providers = {new CultureInfo("en-us"),
                           new CultureInfo("fr-fr"),
                           new CultureInfo("de-de"),
                           new CultureInfo("es-es")};
foreach (byte byteValue in bytes)
{
   foreach (CultureInfo provider in providers)
      Console.Write("{0,3} ({1})      ",
                    byteValue.ToString(provider), provider.Name);

   Console.WriteLine();
}
// The example displays the following output to the console:
//      0 (en-US)        0 (fr-FR)        0 (de-DE)        0 (es-ES)
//      1 (en-US)        1 (fr-FR)        1 (de-DE)        1 (es-ES)
//     14 (en-US)       14 (fr-FR)       14 (de-DE)       14 (es-ES)
//    168 (en-US)      168 (fr-FR)      168 (de-DE)      168 (es-ES)
//    255 (en-US)      255 (fr-FR)      255 (de-DE)      255 (es-ES)
let bytes = [| 0; 1; 14; 168; 255 |]
let providers = 
    [ CultureInfo "en-us"
      CultureInfo "fr-fr"
      CultureInfo "de-de"
      CultureInfo "es-es" ]

for byteValue in bytes do
    for provider in providers do
        printf $"{byteValue.ToString provider,3} ({provider.Name})      " 

    printfn ""

// The example displays the following output to the console:
//      0 (en-US)        0 (fr-FR)        0 (de-DE)        0 (es-ES)
//      1 (en-US)        1 (fr-FR)        1 (de-DE)        1 (es-ES)
//     14 (en-US)       14 (fr-FR)       14 (de-DE)       14 (es-ES)
//    168 (en-US)      168 (fr-FR)      168 (de-DE)      168 (es-ES)
//    255 (en-US)      255 (fr-FR)      255 (de-DE)      255 (es-ES)
Dim bytes() As Byte = {0, 1, 14, 168, 255}
Dim providers() As CultureInfo = {New CultureInfo("en-us"), _
                                  New CultureInfo("fr-fr"), _
                                  New CultureInfo("de-de"), _
                                  New CultureInfo("es-es")}
For Each byteValue As Byte In bytes
   For Each provider As CultureInfo In providers
      Console.Write("{0,3} ({1})      ", byteValue.ToString(provider), provider.Name)
   Next
   Console.WriteLine()                                        
Next
' The example displays the following output to the console:
'      0 (en-US)        0 (fr-FR)        0 (de-DE)        0 (es-ES)
'      1 (en-US)        1 (fr-FR)        1 (de-DE)        1 (es-ES)
'     14 (en-US)       14 (fr-FR)       14 (de-DE)       14 (es-ES)
'    168 (en-US)      168 (fr-FR)      168 (de-DE)      168 (es-ES)
'    255 (en-US)      255 (fr-FR)      255 (de-DE)      255 (es-ES)

Commenti

Il valore restituito viene formattato con l'identificatore di formato numerico generale ("G").

Il provider parametro è un oggetto che implementa l'interfaccia IFormatProvider . Il GetFormat metodo restituisce un NumberFormatInfo oggetto che fornisce informazioni specifiche delle impostazioni cultura sul formato della stringa restituita da questo metodo. L'oggetto che implementa IFormatProvider può essere uno dei seguenti:

  • Oggetto CultureInfo che rappresenta le impostazioni cultura le cui regole di formattazione devono essere usate.

  • Oggetto NumberFormatInfo che contiene informazioni di formattazione numerica specifiche per questo valore.

  • Oggetto personalizzato che implementa IFormatProvider.

Se provider è o non è null possibile ottenere un NumberFormatInfo oggetto da provider, il valore restituito viene formattato usando l'oggetto NumberFormatInfo per le impostazioni cultura correnti del thread. Per informazioni sulle impostazioni cultura correnti del thread, vedere Thread.CurrentCulture.

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

Vedi anche

Si applica a

ToString(String)

Source:
Byte.cs
Source:
Byte.cs
Source:
Byte.cs

Converte il valore dell'oggetto Byte corrente nella rappresentazione di stringa equivalente, 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.

Restituisce

Rappresentazione di stringa dell'oggetto Byte corrente, formattato come specificato dal parametro format.

Eccezioni

format include un identificatore non supportato. Gli identificatori di formato supportati sono elencati nella sezione Note.

Esempio

L'esempio seguente inizializza un Byte valore e lo visualizza nella console usando ognuna delle stringhe di formato standard supportate e una stringa di formato personalizzata. L'esempio viene eseguito con en-US come impostazioni cultura correnti.

array<String^>^ formats = gcnew array<String^> {"C3", "D4", "e1", "E2", "F1", "G", "N1", 
                                                "P0", "X4", "0000.0000"};
Byte number = 240;
for each (String^ format in formats)
   Console::WriteLine("'{0}' format specifier: {1}", 
                     format, number.ToString(format));

// The example displays the following output to the console if the
// current culture is en-us:
//       'C3' format specifier: $240.000
//       'D4' format specifier: 0240
//       'e1' format specifier: 2.4e+002
//       'E2' format specifier: 2.40E+002
//       'F1' format specifier: 240.0
//       'G' format specifier: 240
//       'N1' format specifier: 240.0
//       'P0' format specifier: 24,000 %
//       'X4' format specifier: 00F0
//       '0000.0000' format specifier: 0240.0000
string[] formats = {"C3", "D4", "e1", "E2", "F1", "G", "N1",
                    "P0", "X4", "0000.0000"};
byte number = 240;
foreach (string format in formats)
   Console.WriteLine("'{0}' format specifier: {1}",
                     format, number.ToString(format));

// The example displays the following output to the console if the
// current culture is en-us:
//       'C3' format specifier: $240.000
//       'D4' format specifier: 0240
//       'e1' format specifier: 2.4e+002
//       'E2' format specifier: 2.40E+002
//       'F1' format specifier: 240.0
//       'G' format specifier: 240
//       'N1' format specifier: 240.0
//       'P0' format specifier: 24,000 %
//       'X4' format specifier: 00F0
//       '0000.0000' format specifier: 0240.0000
let formats = 
    [ "C3"; "D4"; "e1"; "E2"; "F1"; "G"; "N1"
      "P0"; "X4"; "0000.0000" ]
let number = 240uy
for format in formats do
    printfn $"'{format}' format specifier: {number.ToString format}"

// The example displays the following output to the console if the
// current culture is en-us:
//       'C3' format specifier: $240.000
//       'D4' format specifier: 0240
//       'e1' format specifier: 2.4e+002
//       'E2' format specifier: 2.40E+002
//       'F1' format specifier: 240.0
//       'G' format specifier: 240
//       'N1' format specifier: 240.0
//       'P0' format specifier: 24,000 %
//       'X4' format specifier: 00F0
//       '0000.0000' format specifier: 0240.0000
Dim formats() As String = {"C3", "D4", "e1", "E2", "F1", "G", _
                           "N1", "P0", "X4", "0000.0000"}
Dim number As Byte = 240
For Each format As String In formats
   Console.WriteLine("'{0}' format specifier: {1}", _
                     format, number.ToString(format))
Next  
' The example displays the following output to the console if the
' current culture is en-us:
'       'C3' format specifier: $240.000
'       'D4' format specifier: 0240
'       'e1' format specifier: 2.4e+002
'       'E2' format specifier: 2.40E+002
'       'F1' format specifier: 240.0       
'       'G' format specifier: 240
'       'N1' format specifier: 240.0
'       'P0' format specifier: 24,000 %
'       'X4' format specifier: 00F0
'       '0000.0000' format specifier: 0240.0000

Commenti

Il format parametro può essere una stringa di formato numerico standard o personalizzata. Tutte le stringhe di formato numerico standard diverse da "R" (o "r") sono supportate, come tutti i caratteri numerici personalizzati. Se format è null o una stringa vuota (""), il valore restituito viene formattato con l'identificatore di formato numerico generale ("G").

Il valore restituito di questa funzione viene formattato usando l'oggetto NumberFormatInfo per le impostazioni cultura correnti del thread. Per informazioni sulle impostazioni cultura correnti del thread, vedere Thread.CurrentCulture. Per fornire informazioni di formattazione per le impostazioni cultura diverse dalle impostazioni cultura correnti, chiamare il Byte.ToString(String, IFormatProvider) metodo .

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

Vedi anche

Si applica a

ToString(String, IFormatProvider)

Source:
Byte.cs
Source:
Byte.cs
Source:
Byte.cs

Converte il valore dell'oggetto Byte corrente 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 dell'oggetto Byte corrente, formattato come specificato dai parametri format e provider.

Implementazioni

Eccezioni

format include un identificatore non supportato. Gli identificatori di formato supportati sono elencati nella sezione Note.

Esempio

Nell'esempio seguente viene usata la stringa di formato "N" standard e quattro oggetti diversi CultureInfo per visualizzare la rappresentazione stringa di un valore di byte nella console.

Byte byteValue = 250;
array<CultureInfo^>^ providers = gcnew array<CultureInfo^> { gcnew CultureInfo("en-us"), 
                                                             gcnew CultureInfo("fr-fr"), 
                                                             gcnew CultureInfo("es-es"), 
                                                             gcnew CultureInfo("de-de")}; 

for each (CultureInfo^ provider in providers) 
   Console::WriteLine("{0} ({1})", 
                     byteValue.ToString("N2", provider), provider->Name);
// The example displays the following output to the console:
//       250.00 (en-US)
//       250,00 (fr-FR)
//       250,00 (es-ES)
//       250,00 (de-DE)
byte byteValue = 250;
CultureInfo[] providers = {new CultureInfo("en-us"),
                           new CultureInfo("fr-fr"),
                           new CultureInfo("es-es"),
                           new CultureInfo("de-de")};

foreach (CultureInfo provider in providers)
   Console.WriteLine("{0} ({1})",
                     byteValue.ToString("N2", provider), provider.Name);
// The example displays the following output to the console:
//       250.00 (en-US)
//       250,00 (fr-FR)
//       250,00 (es-ES)
//       250,00 (de-DE)
let byteValue = 250uy
let providers = 
    [ CultureInfo "en-us"
      CultureInfo "fr-fr"
      CultureInfo "es-es"
      CultureInfo "de-de" ]

for provider in providers do
    printfn $"""{byteValue.ToString("N2", provider)} ({provider.Name})"""

// The example displays the following output to the console:
//       250.00 (en-US)
//       250,00 (fr-FR)
//       250,00 (es-ES)
//       250,00 (de-DE)
Dim byteValue As Byte = 250
Dim providers() As CultureInfo = {New CultureInfo("en-us"), _
                                  New CultureInfo("fr-fr"), _
                                  New CultureInfo("es-es"), _
                                  New CultureInfo("de-de")} 
For Each provider As CultureInfo In providers 
   Console.WriteLine("{0} ({1})", _
                     byteValue.ToString("N2", provider), provider.Name)
Next   
' The example displays the following output to the console:
'       250.00 (en-US)
'       250,00 (fr-FR)
'       250,00 (es-ES)
'       250,00 (de-DE)

Commenti

Il ToString(String, IFormatProvider) metodo formatta un Byte valore in un formato specificato di impostazioni cultura specificate. Per formattare un numero usando il formato predefinito ("G") delle impostazioni cultura correnti, chiamare il ToString() metodo . Per formattare un numero usando un formato specificato delle impostazioni cultura correnti, chiamare il ToString(String) metodo .

Il format parametro può essere una stringa di formato numerico standard o personalizzata. Tutte le stringhe di formato numerico standard diverse da "R" (o "r") sono supportate, come tutti i caratteri numerici personalizzati. Se format è null o una stringa vuota (""), il valore restituito di questo metodo viene formattato con l'identificatore di formato numerico generale ("G").

Il provider parametro è un oggetto che implementa l'interfaccia IFormatProvider . Il GetFormat metodo restituisce un NumberFormatInfo oggetto che fornisce informazioni specifiche delle impostazioni cultura sul formato della stringa restituita da questo metodo. L'oggetto che implementa IFormatProvider può essere uno dei seguenti:

  • Oggetto CultureInfo che rappresenta le impostazioni cultura le cui regole di formattazione devono essere usate.

  • Oggetto NumberFormatInfo che contiene informazioni di formattazione numerica specifiche per questo valore.

  • Oggetto personalizzato che implementa IFormatProvider.

Se provider è o non è null possibile ottenere un NumberFormatInfo oggetto da provider, il valore restituito viene formattato usando l'oggetto NumberFormatInfo per le impostazioni cultura correnti del thread. Per informazioni sulle impostazioni cultura correnti del thread, vedere Thread.CurrentCulture.

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

Vedi anche

Si applica a

ToString()

Source:
Byte.cs
Source:
Byte.cs
Source:
Byte.cs

Converte il valore dell'oggetto Byte corrente 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 di questo oggetto, composto da una sequenza di cifre comprese tra 0 e 9 senza zeri iniziali.

Esempio

Nell'esempio seguente viene visualizzata una matrice di valori di byte. Si noti che il ToString() metodo non viene chiamato in modo esplicito nell'esempio. Viene invece chiamato in modo implicito, a causa dell'uso della funzionalità di formattazione composita , l'esempio F# usa l'interpolazione delle stringhe.

array<Byte>^ bytes = gcnew array<Byte> {0, 1, 14, 168, 255};
for each (Byte byteValue in bytes)
   Console::WriteLine(byteValue);
// The example displays the following output to the console if the current
// culture is en-US:
//       0
//       1
//       14
//       168
//       255
byte[] bytes = {0, 1, 14, 168, 255};
foreach (byte byteValue in bytes)
   Console.WriteLine(byteValue);
// The example displays the following output to the console if the current
// culture is en-US:
//       0
//       1
//       14
//       168
//       255
let bytes = [| 0; 1; 14; 168; 255 |]
for byteValue in bytes do
    printfn $"{byteValue}"

// The example displays the following output to the console if the current
// culture is en-US:
//       0
//       1
//       14
//       168
//       255
Dim bytes() As Byte = {0, 1, 14, 168, 255}
For Each byteValue As Byte In Bytes
   Console.WriteLine(byteValue)
Next   
' The example displays the following output to the console if the current
' culture is en-US:
'       0
'       1
'       14
'       168
'       255

Commenti

Il valore restituito viene formattato con l'identificatore di formato numerico generale ("G") e l'oggetto NumberFormatInfo per le impostazioni cultura correnti del thread. Per definire la formattazione della rappresentazione stringa del Byte valore, chiamare il ToString metodo . Per definire sia gli identificatori di formato che le impostazioni cultura usate per creare la rappresentazione stringa di un Byte valore, chiamare il ToString metodo .

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

Per informazioni sulle impostazioni cultura correnti del thread, vedere Thread.CurrentCulture.

Si applica a