UInt64.ToString Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
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:
- UInt64.cs
- Źródło:
- UInt64.cs
- Źródło:
- UInt64.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 składająca się z sekwencji cyfr od 0 do 9 bez znaku lub zer wiodących.
Implementuje
Przykłady
Poniższy przykład formatuje 64-bitową wartość całkowitą z podpisem 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 };
ulong value = 18709243;
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
// 18709243 18709243 18709243
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 = 18709243uL
printfn $" {getName ci[0],12} {getName ci[1],12} {getName ci[2],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
// 18709243 18709243 18709243
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 ULong = 18709243
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
' 18709243 18709243 18709243
Uwagi
Metoda ToString(IFormatProvider) formatuje UInt64 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:
- UInt64.cs
- Źródło:
- UInt64.cs
- Źródło:
- UInt64.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 format
parametr .
Wyjątki
Parametr format
jest nieprawidłowy.
Przykłady
Poniższy przykład przedstawia 64-bitową niepodpisaną wartość całkowitą 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()
{
ulong value = 217960834;
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: 217960834
// C: $217,960,834.00
// D3: 217960834
// E2: 2.18E+008
// e3: 2.180e+008
// F: 217960834.00
// N: 217,960,834.00
// P: 21,796,083,400.00 %
// X: CFDD182
// 000000.0: 217960834.0
// #.0: 217960834.0
// 00000000;(0);**Zero**: 217960834
let value = 217960834uL
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: 217960834
// C: $217,960,834.00
// D3: 217960834
// E2: 2.18E+008
// e3: 2.180e+008
// F: 217960834.00
// N: 217,960,834.00
// P: 21,796,083,400.00 %
// X: CFDD182
// 000000.0: 217960834.0
// #.0: 217960834.0
// 00000000(0)**Zero**: 217960834
Imports System.Globalization
Module Example
Public Sub Main()
Dim value As ULong = 217960834
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: 217960834
' C: $217,960,834.00
' D3: 217960834
' E2: 2.18E+008
' e3: 2.180e+008
' F: 217960834.00
' N: 217,960,834.00
' P: 21,796,083,400.00 %
' X: CFDD182
' 000000.0: 217960834.0
' #.0: 217960834.0
' 00000000;(0);**Zero**: 217960834
Uwagi
Metoda ToString(String) formatuje UInt64 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 UInt64 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:
Aby uzyskać więcej informacji na temat specyfikatorów formatu liczbowego, zobacz Standardowe ciągi formatu liczbowego i Niestandardowe ciągi formatu liczbowego.
Aby uzyskać więcej informacji na temat obsługi formatowania na platformie .NET, zobacz Typy 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:
- UInt64.cs
- Źródło:
- UInt64.cs
- Źródło:
- UInt64.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"};
ulong value = 22224021;
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: 22224021
// G format using fr-FR culture: 22224021
// G format using es-ES culture: 22224021
//
// C format using en-US culture: $22,224,021.00
// C format using fr-FR culture: 22 224 021,00 €
// C format using es-ES culture: 22.224.021,00 €
//
// D4 format using en-US culture: 22224021
// D4 format using fr-FR culture: 22224021
// D4 format using es-ES culture: 22224021
//
// E2 format using en-US culture: 2.22E+007
// E2 format using fr-FR culture: 2,22E+007
// E2 format using es-ES culture: 2,22E+007
//
// F format using en-US culture: 22224021.00
// F format using fr-FR culture: 22224021,00
// F format using es-ES culture: 22224021,00
//
// N format using en-US culture: 22,224,021.00
// N format using fr-FR culture: 22 224 021,00
// N format using es-ES culture: 22.224.021,00
//
// P format using en-US culture: 2,222,402,100.00 %
// P format using fr-FR culture: 2 222 402 100,00 %
// P format using es-ES culture: 2.222.402.100,00 %
//
// X2 format using en-US culture: 1531C95
// X2 format using fr-FR culture: 1531C95
// X2 format using es-ES culture: 1531C95
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 = 22224021uL
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: 22224021
// G format using fr-FR culture: 22224021
// G format using es-ES culture: 22224021
//
// C format using en-US culture: $22,224,021.00
// C format using fr-FR culture: 22 224 021,00 €
// C format using es-ES culture: 22.224.021,00 €
//
// D4 format using en-US culture: 22224021
// D4 format using fr-FR culture: 22224021
// D4 format using es-ES culture: 22224021
//
// E2 format using en-US culture: 2.22E+007
// E2 format using fr-FR culture: 2,22E+007
// E2 format using es-ES culture: 2,22E+007
//
// F format using en-US culture: 22224021.00
// F format using fr-FR culture: 22224021,00
// F format using es-ES culture: 22224021,00
//
// N format using en-US culture: 22,224,021.00
// N format using fr-FR culture: 22 224 021,00
// N format using es-ES culture: 22.224.021,00
//
// P format using en-US culture: 2,222,402,100.00 %
// P format using fr-FR culture: 2 222 402 100,00 %
// P format using es-ES culture: 2.222.402.100,00 %
//
// X2 format using en-US culture: 1531C95
// X2 format using fr-FR culture: 1531C95
// X2 format using es-ES culture: 1531C95
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 ULong = 22224021
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: 22224021
' G format using fr-FR culture: 22224021
' G format using es-ES culture: 22224021
'
' C format using en-US culture: $22,224,021.00
' C format using fr-FR culture: 22 224 021,00 €
' C format using es-ES culture: 22.224.021,00 €
'
' D4 format using en-US culture: 22224021
' D4 format using fr-FR culture: 22224021
' D4 format using es-ES culture: 22224021
'
' E2 format using en-US culture: 2.22E+007
' E2 format using fr-FR culture: 2,22E+007
' E2 format using es-ES culture: 2,22E+007
'
' F format using en-US culture: 22224021.00
' F format using fr-FR culture: 22224021,00
' F format using es-ES culture: 22224021,00
'
' N format using en-US culture: 22,224,021.00
' N format using fr-FR culture: 22 224 021,00
' N format using es-ES culture: 22.224.021,00
'
' P format using en-US culture: 2,222,402,100.00 %
' P format using fr-FR culture: 2 222 402 100,00 %
' P format using es-ES culture: 2.222.402.100,00 %
'
' X2 format using en-US culture: 1531C95
' X2 format using fr-FR culture: 1531C95
' X2 format using es-ES culture: 1531C95
Uwagi
Metoda ToString(String, IFormatProvider) formatuje UInt64 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 UInt64 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:
Aby uzyskać więcej informacji na temat specyfikatorów formatu liczbowego, zobacz Standardowe ciągi formatu liczbowego i Niestandardowe ciągi formatu liczbowego.
Aby uzyskać więcej informacji na temat formatowania, zobacz Typy 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 UInt64 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ż
- Parse(String)
- Typy formatowania na platformie .NET
- Instrukcje: Uzupełnianie liczby zerami wiodącymi
- Przykład: .NET Core WinForms Formatting Utility (C#)
- Przykład: .NET Core WinForms Formatting Utility (Visual Basic)
Dotyczy
ToString()
- Źródło:
- UInt64.cs
- Źródło:
- UInt64.cs
- Źródło:
- UInt64.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
Reprezentacja ciągu wartości tego wystąpienia składająca się z sekwencji cyfr od 0 do 9 bez znaku lub zer wiodących.
Przykłady
Poniższy przykład przedstawia UInt64 wartość przy użyciu metody domyślnej ToString() . Wyświetla również reprezentacje ciągów UInt64 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()
{
ulong value = 163249057;
// 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:
// 163249057
//
// G format specifier: 163249057
// C format specifier: $163,249,057.00
// D format specifier: 163249057
// F format specifier: 163249057.00
// N format specifier: 163,249,057.00
// X format specifier: 9BAFBA1
let value = 163249057uL
// 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:
// 163249057
//
// G format specifier: 163249057
// C format specifier: $163,249,057.00
// D format specifier: 163249057
// F format specifier: 163249057.00
// N format specifier: 163,249,057.00
// X format specifier: 9BAFBA1
Module Example
Public Sub Main()
Dim value As ULong = 163249057
' 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:
' 163249057
'
' G format specifier: 163249057
' C format specifier: $163,249,057.00
' D format specifier: 163249057
' F format specifier: 163249057.00
' N format specifier: 163,249,057.00
' X format specifier: 9BAFBA1
Uwagi
Metoda ToString() formatuje UInt64 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
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla