UInt32.ToString メソッド

定義

このインスタンスの数値を、それと等価な文字列形式に変換します。

オーバーロード

ToString(IFormatProvider)

このインスタンスの数値を、指定したカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。

ToString(String)

このインスタンスの数値を、指定した書式を使用して、それと等価な文字列形式に変換します。

ToString(String, IFormatProvider)

このインスタンスの数値を、指定した書式およびカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。

ToString()

このインスタンスの数値を、それと等価な文字列形式に変換します。

ToString(IFormatProvider)

Source:
UInt32.cs
Source:
UInt32.cs
Source:
UInt32.cs

このインスタンスの数値を、指定したカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。

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

パラメーター

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。

戻り値

0 から 9 までの一連の数字で構成され、符号も先行ゼロも含まない、このインスタンスの値の文字列形式。

実装

次の例では、インバリアント カルチャ用の 1 つを含む複数の書式プロバイダーを使用して、16 ビット符号付き整数値の書式を設定します。 この例の出力は、 メソッドによって ToString(IFormatProvider) 返される書式設定された文字列が、書式プロバイダーに関係なく同じであることを示しています。

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

注釈

メソッドは ToString(IFormatProvider)UInt32 指定したカルチャの オブジェクトを使用 NumberFormatInfo して、既定の ("G"、または一般) 形式で値の書式を設定します。 別の形式または現在のカルチャを指定する場合は、次のように メソッドの他のオーバーロードを ToString 使用します。

形式を使用するには カルチャの場合 オーバーロードを使用する
既定の ("G") 形式 既定の (現在の) カルチャ ToString()
特定の形式 既定の (現在の) カルチャ ToString(String)
特定の形式 特定のカルチャ ToString(String, IFormatProvider)

パラメーターは provider 実装です IFormatProvider 。 そのメソッドは GetFormat 、カルチャ固有の NumberFormatInfo 書式設定情報を提供する オブジェクトを返します。 ただし、 のプロパティ NumberFormatInfo は、一般的な数値書式指定子 ("G") で書式設定する場合には使用されません。

こちらもご覧ください

適用対象

ToString(String)

Source:
UInt32.cs
Source:
UInt32.cs
Source:
UInt32.cs

このインスタンスの数値を、指定した書式を使用して、それと等価な文字列形式に変換します。

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

パラメーター

format
String

数値書式指定文字列。

戻り値

format で指定された、このインスタンスの値の文字列形式。

例外

format パラメーターが正しくありません。

次の例では、各標準書式指定文字列といくつかのカスタム書式指定文字列を使用して、32 ビット符号なし整数値を表示します。

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

注釈

メソッドは ToString(String) 、現在の UInt32 カルチャの規則を表す オブジェクトを NumberFormatInfo 使用して、指定した形式で値の書式を設定します。 既定の ("G"、または一般的な) 形式を使用する場合、または別のカルチャを指定する場合は、次のように メソッドの他のオーバーロードを ToString 使用します。

形式を使用するには カルチャの場合 オーバーロードを使用する
既定の ("G") 形式 既定の (現在の) カルチャ ToString()
既定の ("G") 形式 特定のカルチャ ToString(IFormatProvider)
特定の形式 特定のカルチャ ToString(String, IFormatProvider)

パラメーターには format 、任意の有効な 標準数値書式指定文字列、または カスタム数値書式指定文字列の任意の組み合わせを指定できます。 が または nullString.Empty場合format、現在UInt32のオブジェクトの戻り値は、一般的な書式指定子 ("G") で書式設定されます。 が他の値の場合 format 、 メソッドは を FormatExceptionスローします。

.NET では、以下の書式設定に関するトピックで詳しく説明されている広範な書式設定のサポートが提供されています。

返される文字列の形式は、現在のカルチャの NumberFormatInfo オブジェクトによって決まります。 パラメーターに format 応じて、このオブジェクトは、出力文字列のグループ区切り記号や小数点記号などの記号を制御します。 現在のカルチャ以外のカルチャの書式設定情報を提供するには、 オーバーロードを ToString(String, IFormatProvider) 呼び出します。

こちらもご覧ください

適用対象

ToString(String, IFormatProvider)

Source:
UInt32.cs
Source:
UInt32.cs
Source:
UInt32.cs

このインスタンスの数値を、指定した書式およびカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。

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

パラメーター

format
String

数値書式指定文字列。

provider
IFormatProvider

このインスタンスに関するカルチャ固有の書式情報を提供するオブジェクト。

戻り値

format および provider で指定された、このインスタンスの値の文字列形式。

実装

例外

format パラメーターが正しくありません。

次の例では、標準の数値書式指定子と特定 CultureInfo のオブジェクトの数を使用して、32 ビット符号なし整数値を表示します。

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

注釈

メソッドは ToString(String, IFormatProvider)UInt32 指定したカルチャの オブジェクトを使用して、 NumberFormatInfo 指定した形式で値の書式を設定します。 既定の形式またはカルチャ設定を使用する場合は、次のように メソッドの他のオーバーロードを ToString 使用します。

形式を使用するには カルチャの場合 オーバーロードを使用する
既定の ("G") 形式 既定の (現在の) カルチャ ToString()
既定の ("G") 形式 特定のカルチャ ToString(IFormatProvider)
特定の形式 既定の (現在の) カルチャ ToString(String)

パラメーターには format 、任意の有効な 標準数値書式指定文字列、または カスタム数値書式指定文字列の任意の組み合わせを指定できます。 が または nullString.Empty場合format、現在UInt32のオブジェクトの戻り値は、一般的な書式指定子 ("G") で書式設定されます。 が他の値の場合 format 、 メソッドは を FormatExceptionスローします。

.NET では、以下の書式設定に関するトピックで詳しく説明されている広範な書式設定のサポートが提供されています。

パラメーターは provider 実装です IFormatProvider 。 そのメソッドは GetFormatNumberFormatInfo このメソッドによって返される文字列の形式に関するカルチャ固有の情報を提供する オブジェクトを返します。 メソッドがToString(String, IFormatProvider)呼び出されると、パラメーターの IFormatProvider.GetFormat メソッドがprovider呼び出され、型をType表すオブジェクトがNumberFormatInfo渡されます。 次に、 メソッドはGetFormat、グループ区切り記号や小数点記号など、現在UInt32の値を書式設定するための情報を提供する オブジェクトを返NumberFormatInfoします。 パラメーターを使用してメソッドに provider 書式設定情報を指定するには、次の ToString(String, IFormatProvider) 3 つの方法があります。

  • 書式設定情報を CultureInfo 提供するカルチャを表す オブジェクトを渡すことができます。 そのメソッドは GetFormat 、そのカルチャの NumberFormatInfo 数値書式情報を提供する オブジェクトを返します。

  • 数値書式情報を提供する実際 NumberFormatInfo のオブジェクトを渡すことができます。 (の実装 GetFormat はそれ自体を返すだけです)。

  • を実装 IFormatProviderするカスタム オブジェクトを渡すことができます。 そのメソッドは GetFormat 、書式設定情報を提供する オブジェクトを NumberFormatInfo インスタンス化して返します。

nullの場合provider、返される文字列の書式設定は、現在のNumberFormatInfoカルチャのオブジェクトに基づきます。

こちらもご覧ください

適用対象

ToString()

Source:
UInt32.cs
Source:
UInt32.cs
Source:
UInt32.cs

このインスタンスの数値を、それと等価な文字列形式に変換します。

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

戻り値

0 から 9 までの一連の数字から構成され、符号または先行ゼロを含まない、このインスタンスの値の文字列形式。

次の例では、既定ToString()のメソッドをUInt32使用して値を表示します。 また、一部の標準書式指定子を UInt32 使用した結果の値の文字列表現も表示されます。 例は、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

注釈

メソッドは ToString() 、現在の UInt32 カルチャの オブジェクトを使用 NumberFormatInfo して、既定の ("G"、または一般) 形式で値の書式を設定します。 別の形式またはカルチャを指定する場合は、次のように メソッドの他のオーバーロードを ToString 使用します。

形式を使用するには カルチャの場合 オーバーロードを使用する
既定の ("G") 形式 特定のカルチャ ToString(IFormatProvider)
特定の形式 既定の (現在の) カルチャ ToString(String)
特定の形式 特定のカルチャ ToString(String, IFormatProvider)

こちらもご覧ください

適用対象