Byte.ToString Metoda

Definicja

Konwertuje wartość bieżącego Byte obiektu na równoważną reprezentację ciągu.

Przeciążenia

ToString(IFormatProvider)

Konwertuje wartość liczbową bieżącego Byte obiektu na równoważną reprezentację ciągu przy użyciu określonych informacji formatowania specyficznych dla kultury.

ToString(String)

Konwertuje wartość bieżącego Byte obiektu na równoważną reprezentację ciągu przy użyciu określonego formatu.

ToString(String, IFormatProvider)

Konwertuje wartość bieżącego Byte obiektu na równoważną reprezentację ciągu przy użyciu określonego formatu i informacji o formatowaniu specyficznym dla kultury.

ToString()

Konwertuje wartość bieżącego Byte obiektu na równoważną reprezentację ciągu.

ToString(IFormatProvider)

Źródło:
Byte.cs
Źródło:
Byte.cs
Źródło:
Byte.cs

Konwertuje wartość liczbową bieżącego Byte obiektu na równoważną reprezentację ciągu przy użyciu określonych informacji formatowania specyficznych dla kultury.

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

Parametry

provider
IFormatProvider

Obiekt, który dostarcza informacje o formatowaniu specyficzne dla kultury.

Zwraca

Ciąg reprezentujący wartość tego obiektu w formacie określonym przez provider parametr .

Implementuje

Przykłady

W poniższym przykładzie iteruje tablicę wartości bajtów i wyświetla każdą z nich w konsoli, wywołując ToString(IFormatProvider) metodę z różnymi dostawcami formatu.

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)

Uwagi

Wartość zwracana jest formatowana za pomocą ogólnego specyfikatora formatu liczbowego ("G").

Parametr provider jest obiektem, który implementuje IFormatProvider interfejs. Metoda GetFormat zwraca NumberFormatInfo obiekt, który dostarcza informacje specyficzne dla kultury dotyczące formatu ciągu zwracanego przez tę metodę. Obiekt, który implementuje IFormatProvider , może być dowolnym z następujących:

  • CultureInfo Obiekt reprezentujący kulturę, której mają być używane reguły formatowania.

  • NumberFormatInfo Obiekt zawierający określone informacje o formatowaniu liczbowym dla tej wartości.

  • Obiekt niestandardowy, który implementuje IFormatProviderelement .

Jeśli provider obiekt jest null lub NumberFormatInfo nie można uzyskać obiektu z providerklasy , zwracana wartość jest formatowana przy użyciu NumberFormatInfo obiektu dla bieżącej kultury wątku. Aby uzyskać informacje o bieżącej kulturze wątku, zobacz Thread.CurrentCulture.

Platforma .NET zapewnia rozbudowaną obsługę formatowania, która została szczegółowo opisana w następujących tematach formatowania:

Zobacz też

Dotyczy

ToString(String)

Źródło:
Byte.cs
Źródło:
Byte.cs
Źródło:
Byte.cs

Konwertuje wartość bieżącego Byte obiektu na równoważną reprezentację ciągu przy użyciu określonego formatu.

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

Parametry

format
String

Ciąg formatu liczbowego.

Zwraca

Reprezentacja ciągu bieżącego Byte obiektu sformatowana zgodnie z parametrem format .

Wyjątki

format zawiera nieobsługiwany specyfikator. Obsługiwane specyfikatory formatu są wymienione w sekcji Uwagi.

Przykłady

Poniższy przykład inicjuje Byte wartość i wyświetla ją w konsoli przy użyciu każdego z obsługiwanych ciągów formatu standardowego i niestandardowego ciągu formatu. Przykład jest uruchamiany z en-US jako bieżącą kulturą.

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

Uwagi

Parametr format może być standardowym lub niestandardowym ciągiem formatu liczbowego. Obsługiwane są wszystkie standardowe ciągi formatu liczbowego inne niż „R” (lub „r”), podobnie jak wszystkie znaki niestandardowych formatów liczbowych. Jeśli format wartość jest null lub ciąg pusty (""), zwracana wartość jest formatowana za pomocą ogólnego specyfikatora formatu liczbowego ("G").

Wartość zwracana tej funkcji jest formatowana przy użyciu NumberFormatInfo obiektu dla bieżącej kultury wątku. Aby uzyskać informacje o bieżącej kulturze wątku, zobacz Thread.CurrentCulture. Aby podać informacje o formatowaniu dla kultur innych niż bieżąca kultura, wywołaj metodę Byte.ToString(String, IFormatProvider) .

Platforma .NET zapewnia rozbudowaną obsługę formatowania, która została szczegółowo opisana w następujących tematach formatowania:

Zobacz też

Dotyczy

ToString(String, IFormatProvider)

Źródło:
Byte.cs
Źródło:
Byte.cs
Źródło:
Byte.cs

Konwertuje wartość bieżącego Byte obiektu na równoważną reprezentację ciągu przy użyciu określonego formatu i informacji o formatowaniu specyficznym dla kultury.

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

Parametry

format
String

Standardowy lub niestandardowy ciąg formatu liczbowego.

provider
IFormatProvider

Obiekt, który dostarcza informacje o formatowaniu specyficzne dla kultury.

Zwraca

Reprezentacja ciągu bieżącego Byte obiektu sformatowana zgodnie z parametrami format i provider .

Implementuje

Wyjątki

format zawiera nieobsługiwany specyfikator. Obsługiwane specyfikatory formatu są wymienione w sekcji Uwagi.

Przykłady

W poniższym przykładzie użyto standardowego ciągu formatu "N" i czterech różnych CultureInfo obiektów, aby wyświetlić reprezentację ciągu wartości bajtu w konsoli.

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)

Uwagi

Metoda ToString(String, IFormatProvider) formatuje Byte wartość w określonym formacie określonej kultury. Aby sformatować liczbę przy użyciu domyślnego formatu ("G") bieżącej kultury, wywołaj metodę ToString() . Aby sformatować liczbę przy użyciu określonego formatu bieżącej kultury, wywołaj metodę ToString(String) .

Parametr format może być standardowym lub niestandardowym ciągiem formatu liczbowego. Obsługiwane są wszystkie standardowe ciągi formatu liczbowego inne niż „R” (lub „r”), podobnie jak wszystkie znaki niestandardowych formatów liczbowych. Jeśli format jest null lub ciąg pusty (""), zwracana wartość tej metody jest formatowana za pomocą ogólnego specyfikatora formatu liczbowego ("G").

Parametr provider jest obiektem, który implementuje IFormatProvider interfejs. Metoda GetFormat zwraca NumberFormatInfo obiekt, który dostarcza informacje specyficzne dla kultury dotyczące formatu ciągu zwracanego przez tę metodę. Obiekt, który implementuje IFormatProvider , może być dowolnym z następujących:

  • CultureInfo Obiekt reprezentujący kulturę, której mają być używane reguły formatowania.

  • NumberFormatInfo Obiekt zawierający określone informacje o formatowaniu liczbowym dla tej wartości.

  • Obiekt niestandardowy, który implementuje IFormatProviderelement .

Jeśli provider obiekt jest null lub NumberFormatInfo nie można uzyskać obiektu z providerklasy , zwracana wartość jest formatowana przy użyciu NumberFormatInfo obiektu dla bieżącej kultury wątku. Aby uzyskać informacje o bieżącej kulturze wątku, zobacz Thread.CurrentCulture.

Platforma .NET zapewnia rozbudowaną obsługę formatowania, która została szczegółowo opisana w następujących tematach formatowania:

Zobacz też

Dotyczy

ToString()

Źródło:
Byte.cs
Źródło:
Byte.cs
Źródło:
Byte.cs

Konwertuje wartość bieżącego Byte obiektu na równoważną reprezentację ciągu.

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

Zwraca

Ciąg reprezentujący wartość tego obiektu, która składa się z sekwencji cyfr z zakresu od 0 do 9 bez zer wiodących.

Przykłady

W poniższym przykładzie jest wyświetlana tablica wartości bajtów. Należy pamiętać, że ToString() metoda nie jest wywoływana jawnie w przykładzie. Zamiast tego jest ona wywoływana niejawnie ze względu na użycie funkcji formatowania złożonego , w przykładzie języka F# jest używana interpolacja ciągów.

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

Uwagi

Wartość zwracana jest formatowana za pomocą ogólnego specyfikatora formatu liczbowego ("G") i NumberFormatInfo obiektu dla bieżącej kultury wątku. Aby zdefiniować formatowanie Byte reprezentacji ciągu wartości, wywołaj metodę ToString . Aby zdefiniować zarówno specyfikatory formatu, jak i kulturę używaną do tworzenia reprezentacji ciągu wartości, wywołaj metodę ByteToString .

Platforma .NET zapewnia rozbudowaną obsługę formatowania, która została szczegółowo opisana w następujących tematach formatowania:

Aby uzyskać informacje o bieżącej kulturze wątku, zobacz Thread.CurrentCulture.

Dotyczy