UInt32.ToString Metoda

Definicja

Konwertuje wartość liczbową tego wystąpienia na równoważną reprezentację w postaci ciągu.

Przeciążenia

ToString(IFormatProvider)

Konwertuje wartość liczbową tego wystąpienia na równoważną reprezentację w postaci ciągu przy użyciu podanych danych formatowania specyficznych dla kultury.

ToString(String)

Konwertuje wartość liczbową tego wystąpienia na równoważną reprezentację ciągu przy użyciu określonego formatu.

ToString(String, IFormatProvider)

Konwertuje wartość liczbową tego wystąpienia na równoważną reprezentację w postaci ciągu przy użyciu podanego formatu i informacji specyficznych dla kultury.

ToString()

Konwertuje wartość liczbową tego wystąpienia na równoważną reprezentację w postaci ciągu.

ToString(IFormatProvider)

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

Konwertuje wartość liczbową tego wystąpienia na równoważną reprezentację w postaci ciągu przy użyciu podanych danych 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

Reprezentacja ciągu wartości tego wystąpienia, która składa się z sekwencji cyfr od 0 do 9 bez znaku lub zer wiodących.

Implementuje

Przykłady

Poniższy przykład formatuje 16-bitową wartość całkowitą ze znakiem przy użyciu kilku dostawców formatu, w tym jednego dla niezmiennej kultury. Dane wyjściowe z przykładu ilustrują, że sformatowany ciąg zwrócony przez ToString(IFormatProvider) metodę jest taki sam, niezależnie od dostawcy formatu.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      // Define an array of CultureInfo objects.
      CultureInfo[] ci = { new CultureInfo("en-US"), 
                           new CultureInfo("fr-FR"), 
                           CultureInfo.InvariantCulture }; 
      uint value = 1870924;
      Console.WriteLine("  {0,12}   {1,12}   {2,12}", 
                        GetName(ci[0]), GetName(ci[1]), GetName(ci[2])); 
      Console.WriteLine("  {0,12}   {1,12}   {2,12}", 
                        value.ToString(ci[0]), value.ToString(ci[1]), value.ToString(ci[2]));   
   }

   private static string GetName(CultureInfo ci)
   {
      if (ci.Equals(CultureInfo.InvariantCulture))
         return "Invariant";
      else
         return ci.Name;         
   }
}
// The example displays the following output:
//             en-US          fr-FR      Invariant
//           1870924        1870924        1870924
open System.Globalization

let getName (ci: CultureInfo) =
    if ci.Equals CultureInfo.InvariantCulture then
        "Invariant"
    else
        ci.Name         

// Define an array of CultureInfo objects.
let ci = 
    [| CultureInfo "en-US" 
       CultureInfo "fr-FR"
       CultureInfo.InvariantCulture |]

let value = 1870924u

printfn $"  {getName ci[0],12}   {getName ci[1],12}   {getName ci[3],12}"
printfn $"  {value.ToString ci[0],12}   {value.ToString ci[1],12}   {value.ToString ci[2],12}"
// The example displays the following output:
//             en-US          fr-FR      Invariant
//           1870924        1870924        1870924
Imports System.Globalization

Module Example
   Public Sub Main()
      ' Define an array of CultureInfo objects.
      Dim ci() As CultureInfo = { New CultureInfo("en-US"), _
                                  New CultureInfo("fr-FR"), _
                                  CultureInfo.InvariantCulture } 
      Dim value As UInteger = 1870924
      Console.WriteLine("  {0,12}   {1,12}   {2,12}", _
                        GetName(ci(0)), GetName(ci(1)), GetName(ci(2))) 
      Console.WriteLine("  {0,12}   {1,12}   {2,12}", _
                        value.ToString(ci(0)), value.ToString(ci(1)), value.ToString(ci(2)))            
      
   End Sub
   
   Private Function GetName(ci As CultureInfo) As String
      If ci.Equals(CultureInfo.InvariantCulture) Then
         Return "Invariant"
      Else
         Return ci.Name
      End If   
   End Function
End Module
' The example displays the following output:
'        en-US          fr-FR      Invariant
'      1870924        1870924        1870924

Uwagi

Metoda ToString(IFormatProvider) formatuje UInt32 wartość w domyślnym formacie ("G" lub ogólnym) przy użyciu NumberFormatInfo obiektu określonej kultury. Jeśli chcesz określić inny format lub bieżącą kulturę, użyj innych przeciążeń ToString metody w następujący sposób:

Aby użyć formatu Dla kultury Używanie przeciążenia
Domyślny format ("G") Domyślna (bieżąca) kultura ToString()
Określony format Domyślna (bieżąca) kultura ToString(String)
Określony format Określona kultura ToString(String, IFormatProvider)

Parametr provider jest implementacją IFormatProvider . Metoda GetFormat zwraca NumberFormatInfo obiekt, który udostępnia informacje o formatowaniu specyficznym dla kultury. Jednak żadna z właściwości obiektu NumberFormatInfo nie jest używana podczas formatowania za pomocą ogólnego specyfikatora formatu liczbowego ("G").

Zobacz też

Dotyczy

ToString(String)

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

Konwertuje wartość liczbową tego wystąpienia 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 wartości tego wystąpienia określona przez formatparametr .

Wyjątki

Parametr format jest nieprawidłowy.

Przykłady

Poniższy przykład przedstawia 32-bitową wartość całkowitą bez znaku przy użyciu każdego standardowego ciągu formatu i niektórych ciągów formatu niestandardowego.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      uint value = 2179608;
      string[] specifiers = { "G", "C", "D3", "E2", "e3", "F", 
                              "N", "P", "X", "000000.0", "#.0", 
                              "00000000;(0);**Zero**" };
      
      foreach (string specifier in specifiers)
         Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
   }
}
// The example displays the following output:
//       G: 2179608
//       C: $2,179,608.00
//       D3: 2179608
//       E2: 2.18E+006
//       e3: 2.180e+006
//       F: 2179608.00
//       N: 2,179,608.00
//       P: 217,960,800.00 %
//       X: 214218
//       000000.0: 2179608.0
//       #.0: 2179608.0
//       00000000;(0);**Zero**: 02179608
let value = 2179608u
let specifiers = 
    [| "G"; "C"; "D3"; "E2"; "e3"; "F" 
       "N"; "P"; "X"; "000000.0"; "#.0" 
       "00000000(0)**Zero**" |]

for specifier in specifiers do
    printfn $"{specifier}: {value.ToString specifier}"
// The example displays the following output:
//       G: 2179608
//       C: $2,179,608.00
//       D3: 2179608
//       E2: 2.18E+006
//       e3: 2.180e+006
//       F: 2179608.00
//       N: 2,179,608.00
//       P: 217,960,800.00 %
//       X: 214218
//       000000.0: 2179608.0
//       #.0: 2179608.0
//       00000000(0)**Zero**: 02179608
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim value As UInteger = 2179608 
      Dim specifiers() As String = { "G", "C", "D3", "E2", "e3", "F", _
                                     "N", "P", "X", "000000.0", "#.0", _
                                     "00000000;(0);**Zero**" }
      
      For Each specifier As String In specifiers
         Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
      Next
   End Sub
End Module
' The example displays the following output:
'       G: 2179608
'       C: $2,179,608.00
'       D3: 2179608
'       E2: 2.18E+006
'       e3: 2.180e+006
'       F: 2179608.00
'       N: 2,179,608.00
'       P: 217,960,800.00 %
'       X: 214218
'       000000.0: 2179608.0
'       #.0: 2179608.0
'       00000000;(0);**Zero**: 02179608

Uwagi

Metoda ToString(String) formatuje UInt32 wartość w określonym formacie przy użyciu NumberFormatInfo obiektu reprezentującego konwencje bieżącej kultury. Jeśli chcesz użyć domyślnego formatu ("G" lub ogólnego) lub określić inną kulturę, użyj innych przeciążeń ToString metody w następujący sposób:

Aby użyć formatu Dla kultury Używanie przeciążenia
Domyślny format ("G") Domyślna (bieżąca) kultura ToString()
Domyślny format ("G") Określona kultura ToString(IFormatProvider)
Określony format Określona kultura ToString(String, IFormatProvider)

Parametr format może być dowolnym prawidłowym standardowymi ciągami formatu liczbowego lub dowolną kombinacją niestandardowych ciągów formatu liczbowego. Jeśli format jest równa String.Empty lub jest null, zwracana wartość bieżącego UInt32 obiektu jest sformatowana za pomocą ogólnego specyfikatora formatu ("G"). Jeśli format jest inną wartością, metoda zgłasza wartość FormatException.

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

Format zwracanego ciągu jest określany przez NumberFormatInfo obiekt dla bieżącej kultury. W zależności od parametru format ten obiekt kontroluje symbole, takie jak separator grupy i symbol punktu dziesiętnego w ciągu wyjściowym. Aby podać informacje o formatowaniu kultur innych niż bieżąca kultura, wywołaj ToString(String, IFormatProvider) przeciążenie.

Zobacz też

Dotyczy

ToString(String, IFormatProvider)

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

Konwertuje wartość liczbową tego wystąpienia na równoważną reprezentację w postaci ciągu przy użyciu podanego formatu i informacji specyficznych 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

Ciąg formatu liczbowego.

provider
IFormatProvider

Obiekt, który dostarcza informacje o formatowaniu tego wystąpienia specyficzne dla kultury.

Zwraca

Ciąg reprezentacja wartości tego wystąpienia określona przez format i provider.

Implementuje

Wyjątki

Parametr format jest nieprawidłowy.

Przykłady

Poniższy przykład przedstawia 32-bitową wartość całkowitą bez znaku przy użyciu standardowych specyfikatorów formatu liczbowego i wielu określonych CultureInfo obiektów.

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") };
      string[] specifiers = {"G", "C", "D4", "E2", "F", "N", "P", "X2"}; 
      uint value = 2222402;
      
      foreach (string specifier in specifiers)
      {
         foreach (CultureInfo culture in cultures)
            Console.WriteLine("{0,2} format using {1} culture: {2, 18}",  
                              specifier, culture.Name, 
                              value.ToString(specifier, culture));
         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//        G format using en-US culture:            2222402
//        G format using fr-FR culture:            2222402
//        G format using es-ES culture:            2222402
//       
//        C format using en-US culture:      $2,222,402.00
//        C format using fr-FR culture:     2 222 402,00 €
//        C format using es-ES culture:     2.222.402,00 €
//       
//       D4 format using en-US culture:            2222402
//       D4 format using fr-FR culture:            2222402
//       D4 format using es-ES culture:            2222402
//       
//       E2 format using en-US culture:          2.22E+006
//       E2 format using fr-FR culture:          2,22E+006
//       E2 format using es-ES culture:          2,22E+006
//       
//        F format using en-US culture:         2222402.00
//        F format using fr-FR culture:         2222402,00
//        F format using es-ES culture:         2222402,00
//       
//        N format using en-US culture:       2,222,402.00
//        N format using fr-FR culture:       2 222 402,00
//        N format using es-ES culture:       2.222.402,00
//       
//        P format using en-US culture:   222,240,200.00 %
//        P format using fr-FR culture:   222 240 200,00 %
//        P format using es-ES culture:   222.240.200,00 %
//       
//       X2 format using en-US culture:             21E942
//       X2 format using fr-FR culture:             21E942
//       X2 format using es-ES culture:             21E942
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 specifiers = 
    [| "G"; "C"; "D4"; "E2"; "F"; "N"; "P"; "X2" |] 
let value = 2222402

for specifier in specifiers do
    for culture in cultures do
        printfn $"{specifier,2} format using {culture.Name} culture: {value.ToString(specifier, culture), 18}"
    printfn ""
// The example displays the following output:
//        G format using en-US culture:            2222402
//        G format using fr-FR culture:            2222402
//        G format using es-ES culture:            2222402
//       
//        C format using en-US culture:      $2,222,402.00
//        C format using fr-FR culture:     2 222 402,00 €
//        C format using es-ES culture:     2.222.402,00 €
//       
//       D4 format using en-US culture:            2222402
//       D4 format using fr-FR culture:            2222402
//       D4 format using es-ES culture:            2222402
//       
//       E2 format using en-US culture:          2.22E+006
//       E2 format using fr-FR culture:          2,22E+006
//       E2 format using es-ES culture:          2,22E+006
//       
//        F format using en-US culture:         2222402.00
//        F format using fr-FR culture:         2222402,00
//        F format using es-ES culture:         2222402,00
//       
//        N format using en-US culture:       2,222,402.00
//        N format using fr-FR culture:       2 222 402,00
//        N format using es-ES culture:       2.222.402,00
//       
//        P format using en-US culture:   222,240,200.00 %
//        P format using fr-FR culture:   222 240 200,00 %
//        P format using es-ES culture:   222.240.200,00 %
//       
//       X2 format using en-US culture:             21E942
//       X2 format using fr-FR culture:             21E942
//       X2 format using es-ES culture:             21E942
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 specifiers() As String = {"G", "C", "D4", "E2", "F", "N", "P", "X2"} 
      Dim value As UInteger = 2222402
      
      For Each specifier As String In specifiers
         For Each culture As CultureInfo In Cultures
            Console.WriteLine("{0,2} format using {1} culture: {2, 18}", _ 
                              specifier, culture.Name, _
                              value.ToString(specifier, culture))

         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'        G format using en-US culture:            2222402
'        G format using fr-FR culture:            2222402
'        G format using es-ES culture:            2222402
'       
'        C format using en-US culture:      $2,222,402.00
'        C format using fr-FR culture:     2 222 402,00 €
'        C format using es-ES culture:     2.222.402,00 €
'       
'       D4 format using en-US culture:            2222402
'       D4 format using fr-FR culture:            2222402
'       D4 format using es-ES culture:            2222402
'       
'       E2 format using en-US culture:          2.22E+006
'       E2 format using fr-FR culture:          2,22E+006
'       E2 format using es-ES culture:          2,22E+006
'       
'        F format using en-US culture:         2222402.00
'        F format using fr-FR culture:         2222402,00
'        F format using es-ES culture:         2222402,00
'       
'        N format using en-US culture:       2,222,402.00
'        N format using fr-FR culture:       2 222 402,00
'        N format using es-ES culture:       2.222.402,00
'       
'        P format using en-US culture:   222,240,200.00 %
'        P format using fr-FR culture:   222 240 200,00 %
'        P format using es-ES culture:   222.240.200,00 %
'       
'       X2 format using en-US culture:             21E942
'       X2 format using fr-FR culture:             21E942
'       X2 format using es-ES culture:             21E942

Uwagi

Metoda ToString(String, IFormatProvider) formatuje UInt32 wartość w określonym formacie przy użyciu NumberFormatInfo obiektu określonej kultury. Jeśli chcesz użyć domyślnych ustawień formatu lub kultury, użyj innych przeciążeń ToString metody w następujący sposób:

Aby użyć formatu Dla kultury Używanie przeciążenia
Domyślny format ("G") Domyślna (bieżąca) kultura ToString()
Domyślny format ("G") Określona kultura ToString(IFormatProvider)
Określony format Domyślna (bieżąca) kultura ToString(String)

Parametr format może być dowolnym prawidłowym standardowymi ciągami formatu liczbowego lub dowolną kombinacją niestandardowych ciągów formatu liczbowego. Jeśli format jest równa String.Empty lub jest null, zwracana wartość bieżącego UInt32 obiektu jest sformatowana za pomocą ogólnego specyfikatora formatu ("G"). Jeśli format jest inną wartością, metoda zgłasza wartość FormatException.

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

Parametr provider jest implementacją IFormatProvider . Metoda GetFormat zwraca NumberFormatInfo obiekt, który dostarcza informacje specyficzne dla kultury dotyczące formatu ciągu zwróconego przez tę metodę. ToString(String, IFormatProvider) Po wywołaniu metody wywołuje metodę provider parametru IFormatProvider.GetFormat i przekazuje go do obiektu reprezentującego TypeNumberFormatInfo typ. Następnie GetFormat metoda zwraca NumberFormatInfo obiekt, który zawiera informacje dotyczące formatowania bieżącej UInt32 wartości, takiej jak symbol separatora grupy lub symbol punktu dziesiętnego. Istnieją trzy sposoby używania parametru do podawania provider informacji o formatowaniu do ToString(String, IFormatProvider) metody:

  • Można przekazać obiekt reprezentujący kulturę CultureInfo , która dostarcza informacje o formatowaniu. Metoda GetFormat zwraca NumberFormatInfo obiekt, który udostępnia informacje o formatowaniu liczbowym dla tej kultury.

  • Możesz przekazać rzeczywisty NumberFormatInfo obiekt, który udostępnia informacje o formatowaniu liczbowym. (Jego implementacja GetFormat po prostu zwraca się).

  • Można przekazać obiekt niestandardowy, który implementuje IFormatProviderobiekt . Metoda GetFormat tworzy wystąpienie i zwraca NumberFormatInfo obiekt, który udostępnia informacje o formatowaniu.

Jeśli provider jest to null, formatowanie zwracanego ciągu jest oparte na NumberFormatInfo obiekcie bieżącej kultury.

Zobacz też

Dotyczy

ToString()

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

Konwertuje wartość liczbową tego wystąpienia na równoważną reprezentację w postaci 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 wystąpienia, składającą się z sekwencji cyfr od 0 do 9 bez znaku lub zer wiodących.

Przykłady

Poniższy przykład przedstawia UInt32 wartość przy użyciu metody domyślnej ToString() . Wyświetla również reprezentacje ciągów UInt32 wartości, która wynika z używania niektórych standardowych specyfikatorów formatu. W przykładach jest używana konwencja formatowania kultury en-US.

using System;

public class Example
{
   public static void Main()
   {
      uint value = 1632490;
      // Display value using default ToString method.
      Console.WriteLine(value.ToString());      
      Console.WriteLine();
      
      // Define an array of format specifiers.
      string[] formats = { "G", "C", "D", "F", "N", "X" };
      // Display value using the standard format specifiers.
      foreach (string format in formats)
         Console.WriteLine("{0} format specifier: {1,16}", 
                           format, value.ToString(format));         
   }
}
// The example displays the following output:
//       1632490
//       
//       G format specifier:          1632490
//       C format specifier:    $1,632,490.00
//       D format specifier:          1632490
//       F format specifier:       1632490.00
//       N format specifier:     1,632,490.00
//       X format specifier:           18E8EA
let value = 1632490u
// Display value using default ToString method.
printfn $"{value.ToString()}\n"      

// Define an array of format specifiers.
let formats = [| "G"; "C"; "D"; "F"; "N"; "X" |]
// Display value using the standard format specifiers.
for format in formats do
    printfn $"{format} format specifier: {value.ToString format,16}"
// The example displays the following output:
//       1632490
//       
//       G format specifier:          1632490
//       C format specifier:    $1,632,490.00
//       D format specifier:          1632490
//       F format specifier:       1632490.00
//       N format specifier:     1,632,490.00
//       X format specifier:           18E8EA
Module Example
   Public Sub Main()
      Dim value As UInteger = 1632490
      ' Display value using default ToString method.
      Console.WriteLine(value.ToString())            
      Console.WriteLine()
      
      ' Define an array of format specifiers.
      Dim formats() As String = { "G", "C", "D", "F", "N", "X" }
      ' Display value using the standard format specifiers.
      For Each format As String In formats
         Console.WriteLine("{0} format specifier: {1,16}", _
                           format, value.ToString(format))         
      Next
   End Sub
End Module
' The example displays the following output:
'       1632490
'       
'       G format specifier:          1632490
'       C format specifier:    $1,632,490.00
'       D format specifier:          1632490
'       F format specifier:       1632490.00
'       N format specifier:     1,632,490.00
'       X format specifier:           18E8EA

Uwagi

Metoda ToString() formatuje UInt32 wartość w domyślnym formacie ("G" lub ogólnym) przy użyciu NumberFormatInfo obiektu bieżącej kultury. Jeśli chcesz określić inny format lub kulturę, użyj innych przeciążeń ToString metody w następujący sposób:

Aby użyć formatu Dla kultury Używanie przeciążenia
Domyślny format ("G") Określona kultura ToString(IFormatProvider)
Określony format Domyślna (bieżąca) kultura ToString(String)
Określony format Określona kultura ToString(String, IFormatProvider)

Zobacz też

Dotyczy