Convert.ToString メソッド

定義

指定した値を等価の文字列形式に変換します。Converts the specified value to its equivalent string representation.

オーバーロード

ToString(Int16, Int32)

16 ビット符号付き整数の値を、指定した基数での等価の文字列形式に変換します。Converts the value of a 16-bit signed integer to its equivalent string representation in a specified base.

ToString(Int16, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 16 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 16-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(UInt64, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 64 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 64-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Decimal, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 10 進数値を等価の文字列形式に変換します。Converts the value of the specified decimal number to its equivalent string representation, using the specified culture-specific formatting information.

ToString(DateTime, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した DateTime の値を等価の文字列形式に変換します。Converts the value of the specified DateTime to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Int32, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 32 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 32-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Double, IFormatProvider)

指定した倍精度浮動小数点数値を等価の文字列形表記に変換します。Converts the value of the specified double-precision floating-point number to its equivalent string representation.

ToString(Int32, Int32)

32 ビット符号付き整数の値を、指定した基数での等価の文字列形式に変換します。Converts the value of a 32-bit signed integer to its equivalent string representation in a specified base.

ToString(SByte, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 8 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 8-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Int64, Int32)

64 ビット符号付き整数の値を、指定した基数でそれと等しい文字列形式に変換します。Converts the value of a 64-bit signed integer to its equivalent string representation in a specified base.

ToString(Object, IFormatProvider)

指定したカルチャ固有の書式情報を使用して、指定したオブジェクトの値を等価の文字列形式に変換します。Converts the value of the specified object to its equivalent string representation using the specified culture-specific formatting information.

ToString(Single, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した単精度浮動小数点数値を等価の文字列形式に変換します。Converts the value of the specified single-precision floating-point number to its equivalent string representation, using the specified culture-specific formatting information.

ToString(String, IFormatProvider)

指定した文字列インスタンスを返します。実際の変換は実行されません。Returns the specified string instance; no actual conversion is performed.

ToString(UInt16, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 16 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 16-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(UInt32, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 32 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 32-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Char, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した Unicode 文字の値を等価の文字列形式に変換します。Converts the value of the specified Unicode character to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Int64, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 64 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 64-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Byte, Int32)

8 ビット符号なし整数値を、指定した基数で表される等価な文字列形式に変換します。Converts the value of an 8-bit unsigned integer to its equivalent string representation in a specified base.

ToString(UInt64)

指定した 64 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 64-bit unsigned integer to its equivalent string representation.

ToString(Boolean, IFormatProvider)

指定したブール値を、それと等しい文字列形式に変換します。Converts the specified Boolean value to its equivalent string representation.

ToString(Byte, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 8 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 8-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Boolean)

指定したブール値を、それと等しい文字列形式に変換します。Converts the specified Boolean value to its equivalent string representation.

ToString(Byte)

指定した 8 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 8-bit unsigned integer to its equivalent string representation.

ToString(Char)

指定した Unicode 文字の値を等価の文字列形式に変換します。Converts the value of the specified Unicode character to its equivalent string representation.

ToString(Decimal)

指定した 10 進数値を、それと等しい文字列形式に変換します。Converts the value of the specified decimal number to its equivalent string representation.

ToString(Double)

指定した倍精度浮動小数点数値を等価の文字列形表記に変換します。Converts the value of the specified double-precision floating-point number to its equivalent string representation.

ToString(Int16)

指定した 16 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 16-bit signed integer to its equivalent string representation.

ToString(DateTime)

指定した DateTime の値を等価の文字列形式に変換します。Converts the value of the specified DateTime to its equivalent string representation.

ToString(Int64)

指定した 64 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 64-bit signed integer to its equivalent string representation.

ToString(Object)

指定したオブジェクトの値を等価の文字列表記に変換します。Converts the value of the specified object to its equivalent string representation.

ToString(SByte)

指定した 8 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 8-bit signed integer to its equivalent string representation.

ToString(Single)

指定した単精度浮動小数点数値を等価の文字列形式に変換します。Converts the value of the specified single-precision floating-point number to its equivalent string representation.

ToString(String)

指定した文字列インスタンスを返します。実際の変換は実行されません。Returns the specified string instance; no actual conversion is performed.

ToString(UInt16)

指定した 16 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 16-bit unsigned integer to its equivalent string representation.

ToString(UInt32)

指定した 32 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 32-bit unsigned integer to its equivalent string representation.

ToString(Int32)

指定した 32 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 32-bit signed integer to its equivalent string representation.

ToString(Int16, Int32)

16 ビット符号付き整数の値を、指定した基数での等価の文字列形式に変換します。Converts the value of a 16-bit signed integer to its equivalent string representation in a specified base.

public:
 static System::String ^ ToString(short value, int toBase);
public static string ToString (short value, int toBase);
static member ToString : int16 * int -> string
Public Shared Function ToString (value As Short, toBase As Integer) As String

パラメーター

value
Int16

変換する 16 ビット符号付き整数。The 16-bit signed integer to convert.

toBase
Int32

戻り値の基数。これは 2、8、10、16 である必要があります。The base of the return value, which must be 2, 8, 10, or 16.

戻り値

基数 valuetoBase の文字列形式。The string representation of value in base toBase.

例外

toBase が 2、8、10、16 のどれでもありません。toBase is not 2, 8, 10, or 16.

次の例では、16ビット符号付き整数の配列内の各要素を、それと等価なバイナリ、8進数、10進数、16進数の文字列形式に変換します。The following example converts each element in an array of 16-bit signed integers to its equivalent binary, octal, decimal, and hexadecimal string representations.

int[] bases = { 2, 8, 10, 16};
short[] numbers = { Int16.MinValue, -13621, -18, 12, 19142, Int16.MaxValue };

foreach (int baseValue in bases)
{
   Console.WriteLine("Base {0} conversion:", baseValue);
   foreach (short number in numbers)
   {
      Console.WriteLine("   {0,-8}  -->  0x{1}", 
                        number, Convert.ToString(number, baseValue));
   }
}
// The example displays the following output:
//       Base 2 conversion:
//          -32768    -->  0x1000000000000000
//          -13621    -->  0x1100101011001011
//          -18       -->  0x1111111111101110
//          12        -->  0x1100
//          19142     -->  0x100101011000110
//          32767     -->  0x111111111111111
//       Base 8 conversion:
//          -32768    -->  0x100000
//          -13621    -->  0x145313
//          -18       -->  0x177756
//          12        -->  0x14
//          19142     -->  0x45306
//          32767     -->  0x77777
//       Base 10 conversion:
//          -32768    -->  0x-32768
//          -13621    -->  0x-13621
//          -18       -->  0x-18
//          12        -->  0x12
//          19142     -->  0x19142
//          32767     -->  0x32767
//       Base 16 conversion:
//          -32768    -->  0x8000
//          -13621    -->  0xcacb
//          -18       -->  0xffee
//          12        -->  0xc
//          19142     -->  0x4ac6
//          32767     -->  0x7fff
Dim bases() As Integer = { 2, 8, 10, 16}
Dim numbers() As Short = { Int16.MinValue, -13621, -18, 12, 19142, _
                           Int16.MaxValue }

For Each base As Integer In bases
   Console.WriteLine("Base {0} conversion:", base)
   For Each number As Short In numbers
      Console.WriteLine("   {0,-8}  -->  0x{1}", _
                        number, Convert.ToString(number, base))
   Next
Next
' The example displays the following output:
'       Base 2 conversion:
'          -32768    -->  0x1000000000000000
'          -13621    -->  0x1100101011001011
'          -18       -->  0x1111111111101110
'          12        -->  0x1100
'          19142     -->  0x100101011000110
'          32767     -->  0x111111111111111
'       Base 8 conversion:
'          -32768    -->  0x100000
'          -13621    -->  0x145313
'          -18       -->  0x177756
'          12        -->  0x14
'          19142     -->  0x45306
'          32767     -->  0x77777
'       Base 10 conversion:
'          -32768    -->  0x-32768
'          -13621    -->  0x-13621
'          -18       -->  0x-18
'          12        -->  0x12
'          19142     -->  0x19142
'          32767     -->  0x32767
'       Base 16 conversion:
'          -32768    -->  0x8000
'          -13621    -->  0xcacb
'          -18       -->  0xffee
'          12        -->  0xc
'          19142     -->  0x4ac6
'          32767     -->  0x7fff
let bases = [2; 8; 10; 16]
let numbers = [ Int16.MinValue; -13621s; -18s; 12s; 19142s; Int16.MaxValue ]

for baseValue in bases do
    printfn "Base %i conversion:" baseValue
    for number in numbers do
        printfn "   % -8i  -->  0x%s" number (Convert.ToString (number, baseValue))
// The example displays the following output:
//     Base 2 conversion:
//        -32768    -->  0x1000000000000000
//        -13621    -->  0x1100101011001011
//        -18       -->  0x1111111111101110
//         12       -->  0x1100
//         19142    -->  0x100101011000110
//         32767    -->  0x111111111111111
//     Base 8 conversion:
//        -32768    -->  0x100000
//        -13621    -->  0x145313
//        -18       -->  0x177756
//         12       -->  0x14
//         19142    -->  0x45306
//         32767    -->  0x77777
//     Base 10 conversion:
//        -32768    -->  0x-32768
//        -13621    -->  0x-13621
//        -18       -->  0x-18
//         12       -->  0x12
//         19142    -->  0x19142
//         32767    -->  0x32767
//     Base 16 conversion:
//        -32768    -->  0x8000
//        -13621    -->  0xcacb
//        -18       -->  0xffee
//         12       -->  0xc
//         19142    -->  0x4ac6
//         32767    -->  0x7fff

注釈

valuetoBase正で、が2、8、または16の場合、返される文字列は、符号と大きさの表現を使用します。If value is positive and toBase is 2, 8, or 16, the returned string uses sign-and-magnitude representation. valuetoBase負の値で、が2、8、または16の場合、返される文字列は2の補数表現を使用します。If value is negative and toBase is 2, 8, or 16, the returned string uses two's complement representation. これは、上位バイトの上位ビット (ビット 15) が符号ビットとして解釈されることを意味します。This means that the high-order bit of the high-order byte (bit 15) is interpreted as the sign bit. 後で数値に変換する文字列を作成するためにメソッドが呼び出された場合、変換を実行するには、同様の数値表現を想定する対応するメソッドを呼び出す必要があります。ToString(Int16, Int32)If the ToString(Int16, Int32) method is called to create a string that will later be converted back to a number, a corresponding method that assumes a similar numeric representation should be called to perform the conversion. このようなConvert.ToInt16(String, Int32)メソッドInt16.Parse(String, NumberStyles)には、とが含まれます。Such methods include Convert.ToInt16(String, Int32) and Int16.Parse(String, NumberStyles).

ToString(Int16, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 16 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 16-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(short value, IFormatProvider ^ provider);
public static string ToString (short value, IFormatProvider provider);
static member ToString : int16 * IFormatProvider -> string
Public Shared Function ToString (value As Short, provider As IFormatProvider) As String

パラメーター

value
Int16

変換する 16 ビット符号付き整数。The 16-bit signed integer to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

次の例では、 NumberFormatInfo負の符号を文字列 "~"、正の符号を文字列 "!" として定義するカスタムクラスを定義しています。The following example defines a custom NumberFormatInfo class that defines its negative sign as the string "~" and its positive sign as the string "!". 次に、 ToString(Int16, IFormatProvider)メソッドを呼び出して、16ビット整数の配列内の各要素を、それと等価な文字列形式に変換します。It then calls the ToString(Int16, IFormatProvider) method to convert each element in an array of 16-bit integers to its equivalent string representation. 変換では、カスタムNumberFormatInfoオブジェクトだけでなく、インバリアントカルチャも使用します。The conversion uses the invariant culture as well as the custom NumberFormatInfo object.

short[] numbers = { Int16.MinValue, Int16.MaxValue};
System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
nfi.NegativeSign = "~";
nfi.PositiveSign = "!";

foreach (short number in numbers)
   Console.WriteLine("{0,-8}  -->  {1,8}", 
                     Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture), 
                     Convert.ToString(number, nfi));
// The example displays the following output:
//       -32768    -->    ~32768
//       32767     -->     32767
Dim numbers() As Short = { Int16.MinValue, Int16.MaxValue}
Dim nfi As New System.Globalization.NumberFormatInfo()
nfi.NegativeSign = "~"
nfi.PositiveSign = "!"

For Each number As Short In numbers
   Console.WriteLine("{0,-8}  -->  {1,8}", _
                     Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture), _
                     Convert.ToString(number, nfi))
Next
' The example displays the following output:
'       -32768    -->    ~32768
'       32767     -->     32767

注釈

この実装はとInt16.ToString(IFormatProvider)同じです。This implementation is identical to Int16.ToString(IFormatProvider).

ToString(UInt64, IFormatProvider)

重要

この API は CLS 準拠ではありません。

指定したカルチャに固有の書式情報を使用して、指定した 64 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 64-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(System::UInt64 value, IFormatProvider ^ provider);
[System.CLSCompliant(false)]
public static string ToString (ulong value, IFormatProvider provider);
static member ToString : uint64 * IFormatProvider -> string
Public Shared Function ToString (value As ULong, provider As IFormatProvider) As String

パラメーター

value
UInt64

変換する 64 ビット符号なし整数。The 64-bit unsigned integer to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

属性

次の例では、 NumberFormatInfo負の符号を文字列 "~"、正の符号を文字列 "!" として定義するカスタムクラスを定義しています。The following example defines a custom NumberFormatInfo class that defines its negative sign as the string "~" and its positive sign as the string "!". 次に、 ToString(UInt64, IFormatProvider)メソッドを呼び出して、符号なし長整数値を等価の文字列形式に変換します。It then calls the ToString(UInt64, IFormatProvider) method to convert an unsigned long integer value to its equivalent string representation. 変換では、インバリアントカルチャとカスタムNumberFormatInfoオブジェクトの両方が使用されます。The conversion uses both the invariant culture and the custom NumberFormatInfo object. 出力は、この書式設定情報が使用されていないことを示します。既定では、"G" 書式指定子に正の値を持つ正の符号が含まれていないためです。The output indicates that this formatting information is not used, because by default the "G" format specifier does not include a positive sign with positive values.

ulong number = UInt64.MaxValue;
System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
nfi.NegativeSign = "~";
nfi.PositiveSign = "!";

Console.WriteLine("{0,-12}  -->  {1,12}",
                  Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture),
                  Convert.ToString(number, nfi));
// The example displays the following output:
//    18446744073709551615  -->  18446744073709551615
Dim number As ULong = UInt64.MaxValue
Dim nfi As New System.Globalization.NumberFormatInfo()
nfi.NegativeSign = "~"
nfi.PositiveSign = "!"

Console.WriteLine("{0,-12}  -->  {1,12}", _
                  Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture), _
                  Convert.ToString(number, nfi))
' The example displays the following output:
'    18446744073709551615  -->  18446744073709551615

注釈

この実装はとUInt64.ToString(IFormatProvider)同じです。This implementation is identical to UInt64.ToString(IFormatProvider).

ToString(Decimal, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 10 進数値を等価の文字列形式に変換します。Converts the value of the specified decimal number to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(System::Decimal value, IFormatProvider ^ provider);
public static string ToString (decimal value, IFormatProvider provider);
static member ToString : decimal * IFormatProvider -> string
Public Shared Function ToString (value As Decimal, provider As IFormatProvider) As String

パラメーター

value
Decimal

変換する 10 進数。The decimal number to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

次の例では、値のDecimal配列内の各要素を、4つの異なるカルチャの等価の文字列形式に変換します。The following example converts each element in an array of Decimal values to its equivalent string representation in four different cultures.

// Define an array of numbers to display.
decimal[] numbers = { 1734231911290.16m, -17394.32921m,
                      3193.23m, 98012368321.684m };
// Define the culture names used to display them.
string[] cultureNames = { "en-US", "fr-FR", "ja-JP", "ru-RU" };

foreach (decimal number in numbers)
{
   Console.WriteLine("{0}:", Convert.ToString(number,
                             System.Globalization.CultureInfo.InvariantCulture));
   foreach (string cultureName in cultureNames)
   {
      System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(cultureName);
      Console.WriteLine("   {0}: {1,20}",
                        culture.Name, Convert.ToString(number, culture));
   }
   Console.WriteLine();
}   
// The example displays the following output:
//    1734231911290.16:
//       en-US:     1734231911290.16
//       fr-FR:     1734231911290,16
//       ja-JP:     1734231911290.16
//       ru-RU:     1734231911290,16
//    
//    -17394.32921:
//       en-US:         -17394.32921
//       fr-FR:         -17394,32921
//       ja-JP:         -17394.32921
//       ru-RU:         -17394,32921
//    
//    3193.23:
//       en-US:              3193.23
//       fr-FR:              3193,23
//       ja-JP:              3193.23
//       ru-RU:              3193,23
//    
//    98012368321.684:
//       en-US:      98012368321.684
//       fr-FR:      98012368321,684
//       ja-JP:      98012368321.684
//       ru-RU:      98012368321,684
' Define an array of numbers to display.
Dim numbers() As Decimal = { 1734231911290.16d, -17394.32921d, _
                             3193.23d, 98012368321.684d }
' Define the culture names used to display them.
Dim cultureNames() As String = { "en-US", "fr-FR", "ja-JP", "ru-RU" }

For Each number As Decimal In numbers
   Console.WriteLine("{0}:", Convert.ToString(number, _
                             System.Globalization.CultureInfo.InvariantCulture))
   For Each cultureName As String In cultureNames
      Dim culture As New System.Globalization.CultureInfo(cultureName)
      Console.WriteLine("   {0}: {1,20}", _
                        culture.Name, Convert.ToString(number, culture))
   Next
   Console.WriteLine()
Next   
' The example displays the following output:
'    1734231911290.16:
'       en-US:     1734231911290.16
'       fr-FR:     1734231911290,16
'       ja-JP:     1734231911290.16
'       ru-RU:     1734231911290,16
'    
'    -17394.32921:
'       en-US:         -17394.32921
'       fr-FR:         -17394,32921
'       ja-JP:         -17394.32921
'       ru-RU:         -17394,32921
'    
'    3193.23:
'       en-US:              3193.23
'       fr-FR:              3193,23
'       ja-JP:              3193.23
'       ru-RU:              3193,23
'    
'    98012368321.684:
'       en-US:      98012368321.684
'       fr-FR:      98012368321,684
'       ja-JP:      98012368321.684
'       ru-RU:      98012368321,684

注釈

この実装はとDecimal.ToString(IFormatProvider)同じです。This implementation is identical to Decimal.ToString(IFormatProvider).

ToString(DateTime, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した DateTime の値を等価の文字列形式に変換します。Converts the value of the specified DateTime to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(DateTime value, IFormatProvider ^ provider);
public static string ToString (DateTime value, IFormatProvider provider);
static member ToString : DateTime * IFormatProvider -> string
Public Shared Function ToString (value As DateTime, provider As IFormatProvider) As String

パラメーター

value
DateTime

変換する日時の値。The date and time value to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

次の例ではDateTime 、8つの異なるカルチャで値を等価の文字列形式に変換します。The following example converts a DateTime value to its equivalent string representation in eight different cultures.

// Specify the date to be formatted using various cultures.
DateTime tDate = new DateTime(2010, 4, 15, 20, 30, 40, 333);
// Specify the cultures.
string[] cultureNames = { "en-US", "es-AR", "fr-FR", "hi-IN",
                          "ja-JP", "nl-NL", "ru-RU", "ur-PK" };

Console.WriteLine("Converting the date {0}: ", 
                  Convert.ToString(tDate, 
                          System.Globalization.CultureInfo.InvariantCulture));

foreach (string cultureName in cultureNames)
{
   System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(cultureName);
   string dateString = Convert.ToString(tDate, culture);
   Console.WriteLine("   {0}:  {1,-12}", 
                     culture.Name, dateString);
}             
// The example displays the following output:
//       Converting the date 04/15/2010 20:30:40:
//          en-US:  4/15/2010 8:30:40 PM
//          es-AR:  15/04/2010 08:30:40 p.m.
//          fr-FR:  15/04/2010 20:30:40
//          hi-IN:  15-04-2010 20:30:40
//          ja-JP:  2010/04/15 20:30:40
//          nl-NL:  15-4-2010 20:30:40
//          ru-RU:  15.04.2010 20:30:40
//          ur-PK:  15/04/2010 8:30:40 PM      
' Specify the date to be formatted using various cultures.
Dim tDate As New Date(2010, 4, 15, 20, 30, 40, 333)
' Specify the cultures.
Dim cultureNames() As String = { "en-US", "es-AR", "fr-FR", "hi-IN", _
                                 "ja-JP", "nl-NL", "ru-RU", "ur-PK" }

Console.WriteLine("Converting the date {0}: ", _
                  Convert.ToString(tDate, _
                          System.Globalization.CultureInfo.InvariantCulture))

For Each cultureName As String In CultureNames
   Dim culture As New System.Globalization.CultureInfo(cultureName)
   Dim dateString As String = Convert.ToString(tDate, culture)
   Console.WriteLine("   {0}:  {1,-12}", _
                     culture.Name, dateString)
Next             
' The example displays the following output:
'       Converting the date 04/15/2010 20:30:40:
'          en-US:  4/15/2010 8:30:40 PM
'          es-AR:  15/04/2010 08:30:40 p.m.
'          fr-FR:  15/04/2010 20:30:40
'          hi-IN:  15-04-2010 20:30:40
'          ja-JP:  2010/04/15 20:30:40
'          nl-NL:  15-4-2010 20:30:40
'          ru-RU:  15.04.2010 20:30:40
'          ur-PK:  15/04/2010 8:30:40 PM      

注釈

この実装はとDateTime.ToString(IFormatProvider)同じです。This implementation is identical to DateTime.ToString(IFormatProvider).

ToString(Int32, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 32 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 32-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(int value, IFormatProvider ^ provider);
public static string ToString (int value, IFormatProvider provider);
static member ToString : int * IFormatProvider -> string
Public Shared Function ToString (value As Integer, provider As IFormatProvider) As String

パラメーター

value
Int32

変換する 32 ビット符号付き整数。The 32-bit signed integer to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

次の例では、 NumberFormatInfo負の符号を文字列 "~"、正の符号を文字列 "!" として定義するカスタムクラスを定義しています。The following example defines a custom NumberFormatInfo class that defines its negative sign as the string "~" and its positive sign as the string "!". 次に、 ToString(Int32, IFormatProvider)メソッドを呼び出して、整数の配列内の各要素を等価の文字列形式に変換します。It then calls the ToString(Int32, IFormatProvider) method to convert each element in an array of integers to its equivalent string representation. 変換では、カスタムNumberFormatInfoオブジェクトだけでなく、インバリアントカルチャも使用します。The conversion uses the invariant culture as well as the custom NumberFormatInfo object.

int[] numbers = { Int32.MinValue, Int32.MaxValue};
System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
nfi.NegativeSign = "~";
nfi.PositiveSign = "!";

foreach (int number in numbers)
   Console.WriteLine("{0,-12}  -->  {1,12}", 
                     Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture), 
                     Convert.ToString(number, nfi));
// The example displays the following output:
//       -2147483648  -->  ~2147483648
//       2147483647  -->  2147483647
Dim numbers() As Integer = { Int32.MinValue, Int32.MaxValue}
Dim nfi As New System.Globalization.NumberFormatInfo()
nfi.NegativeSign = "~"
nfi.PositiveSign = "!"

For Each number As Integer In numbers
   Console.WriteLine("{0,-12}  -->  {1,12}", _
                     Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture), _
                     Convert.ToString(number, nfi))
Next
' The example displays the following output:
'       -2147483648  -->  ~2147483648
'       2147483647   -->  2147483647

注釈

この実装はとInt32.ToString(IFormatProvider)同じです。This implementation is identical to Int32.ToString(IFormatProvider).

ToString(Double, IFormatProvider)

指定した倍精度浮動小数点数値を等価の文字列形表記に変換します。Converts the value of the specified double-precision floating-point number to its equivalent string representation.

public:
 static System::String ^ ToString(double value, IFormatProvider ^ provider);
public static string ToString (double value, IFormatProvider provider);
static member ToString : double * IFormatProvider -> string
Public Shared Function ToString (value As Double, provider As IFormatProvider) As String

パラメーター

value
Double

変換する倍精度浮動小数点数。The double-precision floating-point number to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

次の例では、値のDouble配列内の各要素を、4つの異なるカルチャの等価の文字列形式に変換します。The following example converts each element in an array of Double values to its equivalent string representation in four different cultures.

// Define an array of numbers to display.
double[] numbers = { -1.5345e16, -123.4321, 19092.123, 1.1734231911290e16 };
// Define the culture names used to display them.
string[] cultureNames = { "en-US", "fr-FR", "ja-JP", "ru-RU" };

foreach (double number in numbers)
{
   Console.WriteLine("{0}:", Convert.ToString(number,
                             System.Globalization.CultureInfo.InvariantCulture));
   foreach (string cultureName in cultureNames)
   {
      System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(cultureName);
      Console.WriteLine("   {0}: {1,20}",
                        culture.Name, Convert.ToString(number, culture));
   }
   Console.WriteLine();
}   
// The example displays the following output:
//    -1.5345E+16:
//       en-US:          -1.5345E+16
//       fr-FR:          -1,5345E+16
//       ja-JP:          -1.5345E+16
//       ru-RU:          -1,5345E+16
//    
//    -123.4321:
//       en-US:            -123.4321
//       fr-FR:            -123,4321
//       ja-JP:            -123.4321
//       ru-RU:            -123,4321
//    
//    19092.123:
//       en-US:            19092.123
//       fr-FR:            19092,123
//       ja-JP:            19092.123
//       ru-RU:            19092,123
//    
//    1.173423191129E+16:
//       en-US:   1.173423191129E+16
//       fr-FR:   1,173423191129E+16
//       ja-JP:   1.173423191129E+16
//       ru-RU:   1,173423191129E+16
' Define an array of numbers to display.
Dim numbers() As Double = { -1.5345e16, -123.4321, 19092.123, _
                            1.1734231911290e16 }
' Define the culture names used to display them.
Dim cultureNames() As String = { "en-US", "fr-FR", "ja-JP", "ru-RU" }

For Each number As Double In numbers
   Console.WriteLine("{0}:", Convert.ToString(number, _
                             System.Globalization.CultureInfo.InvariantCulture))
   For Each cultureName As String In cultureNames
      Dim culture As New System.Globalization.CultureInfo(cultureName)
      Console.WriteLine("   {0}: {1,20}", _
                        culture.Name, Convert.ToString(number, culture))
   Next
   Console.WriteLine()
Next   
' The example displays the following output:
'    -1.5345E+16:
'       en-US:          -1.5345E+16
'       fr-FR:          -1,5345E+16
'       ja-JP:          -1.5345E+16
'       ru-RU:          -1,5345E+16
'    
'    -123.4321:
'       en-US:            -123.4321
'       fr-FR:            -123,4321
'       ja-JP:            -123.4321
'       ru-RU:            -123,4321
'    
'    19092.123:
'       en-US:            19092.123
'       fr-FR:            19092,123
'       ja-JP:            19092.123
'       ru-RU:            19092,123
'    
'    1.173423191129E+16:
'       en-US:   1.173423191129E+16
'       fr-FR:   1,173423191129E+16
'       ja-JP:   1.173423191129E+16
'       ru-RU:   1,173423191129E+16

注釈

この実装はと同じです。Double.ToString(IFormatProvider)This implementation is identical to Double.ToString(IFormatProvider)

ToString(Int32, Int32)

32 ビット符号付き整数の値を、指定した基数での等価の文字列形式に変換します。Converts the value of a 32-bit signed integer to its equivalent string representation in a specified base.

public:
 static System::String ^ ToString(int value, int toBase);
public static string ToString (int value, int toBase);
static member ToString : int * int -> string
Public Shared Function ToString (value As Integer, toBase As Integer) As String

パラメーター

value
Int32

変換する 32 ビット符号付き整数。The 32-bit signed integer to convert.

toBase
Int32

戻り値の基数。これは 2、8、10、16 である必要があります。The base of the return value, which must be 2, 8, 10, or 16.

戻り値

基数 valuetoBase の文字列形式。The string representation of value in base toBase.

例外

toBase が 2、8、10、16 のどれでもありません。toBase is not 2, 8, 10, or 16.

次の例では、整数配列の各要素を等価のバイナリ、16進数、10進数、16進数の文字列形式に変換します。The following example converts each element in an integer array to its equivalent binary, hexadecimal, decimal, and hexadecimal string representations.

int[] bases = { 2, 8, 10, 16};
int[] numbers = { Int32.MinValue, -19327543, -13621, -18, 12, 
                             19142, Int32.MaxValue };

foreach (int baseValue in bases)
{
   Console.WriteLine("Base {0} conversion:", baseValue);
   foreach (int number in numbers)
   {
      Console.WriteLine("   {0,-15}  -->  0x{1}", 
                        number, Convert.ToString(number, baseValue));
   }
}
// The example displays the following output:
//    Base 2 conversion:
//       -2147483648      -->  0x10000000000000000000000000000000
//       -19327543        -->  0x11111110110110010001010111001001
//       -13621           -->  0x11111111111111111100101011001011
//       -18              -->  0x11111111111111111111111111101110
//       12               -->  0x1100
//       19142            -->  0x100101011000110
//       2147483647       -->  0x1111111111111111111111111111111
//    Base 8 conversion:
//       -2147483648      -->  0x20000000000
//       -19327543        -->  0x37666212711
//       -13621           -->  0x37777745313
//       -18              -->  0x37777777756
//       12               -->  0x14
//       19142            -->  0x45306
//       2147483647       -->  0x17777777777
//    Base 10 conversion:
//       -2147483648      -->  0x-2147483648
//       -19327543        -->  0x-19327543
//       -13621           -->  0x-13621
//       -18              -->  0x-18
//       12               -->  0x12
//       19142            -->  0x19142
//       2147483647       -->  0x2147483647
//    Base 16 conversion:
//       -2147483648      -->  0x80000000
//       -19327543        -->  0xfed915c9
//       -13621           -->  0xffffcacb
//       -18              -->  0xffffffee
//       12               -->  0xc
//       19142            -->  0x4ac6
//       2147483647       -->  0x7fffffff       
Dim bases() As Integer = { 2, 8, 10, 16}
Dim numbers() As Integer = { Int32.MinValue, -19327543, -13621, -18, 12, _
                             19142, Int32.MaxValue }

For Each base As Integer In bases
   Console.WriteLine("Base {0} conversion:", base)
   For Each number As Integer In numbers
      Console.WriteLine("   {0,-15}  -->  0x{1}", _
                        number, Convert.ToString(number, base))
   Next
Next
' The example displays the following output:
'    Base 2 conversion:
'       -2147483648      -->  0x10000000000000000000000000000000
'       -19327543        -->  0x11111110110110010001010111001001
'       -13621           -->  0x11111111111111111100101011001011
'       -18              -->  0x11111111111111111111111111101110
'       12               -->  0x1100
'       19142            -->  0x100101011000110
'       2147483647       -->  0x1111111111111111111111111111111
'    Base 8 conversion:
'       -2147483648      -->  0x20000000000
'       -19327543        -->  0x37666212711
'       -13621           -->  0x37777745313
'       -18              -->  0x37777777756
'       12               -->  0x14
'       19142            -->  0x45306
'       2147483647       -->  0x17777777777
'    Base 10 conversion:
'       -2147483648      -->  0x-2147483648
'       -19327543        -->  0x-19327543
'       -13621           -->  0x-13621
'       -18              -->  0x-18
'       12               -->  0x12
'       19142            -->  0x19142
'       2147483647       -->  0x2147483647
'    Base 16 conversion:
'       -2147483648      -->  0x80000000
'       -19327543        -->  0xfed915c9
'       -13621           -->  0xffffcacb
'       -18              -->  0xffffffee
'       12               -->  0xc
'       19142            -->  0x4ac6
'       2147483647       -->  0x7fffffff
let bases = [2; 8; 10; 16]
let numbers = [ Int32.MinValue; -19327543; -13621; -18; 12; 19142; Int32.MaxValue ]

for baseValue in bases do
    printfn "Base %i conversion:" baseValue
    for number in numbers do
        printfn "   % -15i  -->  0x%s" number (Convert.ToString (number, baseValue))
// The example displays the following output:
//     Base 2 conversion:
//        -2147483648      -->  0x10000000000000000000000000000000
//        -19327543        -->  0x11111110110110010001010111001001
//        -13621           -->  0x11111111111111111100101011001011
//        -18              -->  0x11111111111111111111111111101110
//         12              -->  0x1100
//         19142           -->  0x100101011000110
//         2147483647      -->  0x1111111111111111111111111111111
//     Base 8 conversion:
//        -2147483648      -->  0x20000000000
//        -19327543        -->  0x37666212711
//        -13621           -->  0x37777745313
//        -18              -->  0x37777777756
//         12              -->  0x14
//         19142           -->  0x45306
//         2147483647      -->  0x17777777777
//     Base 10 conversion:
//        -2147483648      -->  0x-2147483648
//        -19327543        -->  0x-19327543
//        -13621           -->  0x-13621
//        -18              -->  0x-18
//         12              -->  0x12
//         19142           -->  0x19142
//         2147483647      -->  0x2147483647
//     Base 16 conversion:
//        -2147483648      -->  0x80000000
//        -19327543        -->  0xfed915c9
//        -13621           -->  0xffffcacb
//        -18              -->  0xffffffee
//         12              -->  0xc
//         19142           -->  0x4ac6
//         2147483647      -->  0x7fffffff

注釈

valuetoBase正で、が2、8、または16の場合、返される文字列は、符号と大きさの表現を使用します。If value is positive and toBase is 2, 8, or 16, the returned string uses sign-and-magnitude representation. valuetoBase負の値で、が2、8、または16の場合、返される文字列は2の補数表現を使用します。If value is negative and toBase is 2, 8, or 16, the returned string uses two's complement representation. これは、上位バイトの上位ビット (ビット 31) が符号ビットとして解釈されることを意味します。This means that the high-order bit of the highest-order byte (bit 31) is interpreted as the sign bit. 後で数値に変換する文字列を作成するためにメソッドが呼び出された場合、変換を実行するには、同様の数値表現を想定する対応するメソッドを呼び出す必要があります。ToString(Int32, Int32)If the ToString(Int32, Int32) method is called to create a string that will later be converted back to a number, a corresponding method that assumes a similar numeric representation should be called to perform the conversion. このようなConvert.ToInt32(String, Int32)メソッドInt32.Parse(String, NumberStyles)には、とが含まれます。Such methods include Convert.ToInt32(String, Int32) and Int32.Parse(String, NumberStyles).

ToString(SByte, IFormatProvider)

重要

この API は CLS 準拠ではありません。

指定したカルチャに固有の書式情報を使用して、指定した 8 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 8-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(System::SByte value, IFormatProvider ^ provider);
[System.CLSCompliant(false)]
public static string ToString (sbyte value, IFormatProvider provider);
static member ToString : sbyte * IFormatProvider -> string
Public Shared Function ToString (value As SByte, provider As IFormatProvider) As String

パラメーター

value
SByte

変換する 8 ビット符号付き整数。The 8-bit signed integer to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

属性

次の例では、 NumberFormatInfo負の符号を文字列 "~"、正の符号を文字列 "!" として定義するカスタムクラスを定義しています。The following example defines a custom NumberFormatInfo class that defines its negative sign as the string "~" and its positive sign as the string "!". 次に、メソッドConvert.ToString(SByte, IFormatProvider)を呼び出して、符号付きバイト配列内の各要素を等価の文字列形式に変換します。It then calls the Convert.ToString(SByte, IFormatProvider) method to convert each element in signed byte array to its equivalent string representation. 変換では、カスタムNumberFormatInfoオブジェクトだけでなく、インバリアントカルチャも使用します。The conversion uses the invariant culture as well as the custom NumberFormatInfo object.

sbyte[] numbers = { SByte.MinValue, -12, 17, SByte.MaxValue};
System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
nfi.NegativeSign = "~";
nfi.PositiveSign = "!";
foreach (sbyte number in numbers)
   Console.WriteLine(Convert.ToString(number, nfi));
// The example displays the following output:
//       ~128
//       ~12
//       17
//       127      
Dim numbers() As SByte = { SByte.MinValue, -12, 17, SByte.MaxValue}
Dim nfi As New System.Globalization.NumberFormatInfo()
nfi.NegativeSign = "~"
nfi.PositiveSign = "!"
For Each number As SByte In numbers
   Console.WriteLine(Convert.ToString(number, nfi))
Next
' The example displays the following output:
'       ~128
'       ~12
'       17
'       127          

注釈

この実装はとSByte.ToString(IFormatProvider)同じです。This implementation is identical to SByte.ToString(IFormatProvider).

ToString(Int64, Int32)

64 ビット符号付き整数の値を、指定した基数でそれと等しい文字列形式に変換します。Converts the value of a 64-bit signed integer to its equivalent string representation in a specified base.

public:
 static System::String ^ ToString(long value, int toBase);
public static string ToString (long value, int toBase);
static member ToString : int64 * int -> string
Public Shared Function ToString (value As Long, toBase As Integer) As String

パラメーター

value
Int64

変換する 64 ビット符号付き整数。The 64-bit signed integer to convert.

toBase
Int32

戻り値の基数。これは 2、8、10、16 である必要があります。The base of the return value, which must be 2, 8, 10, or 16.

戻り値

基数 valuetoBase の文字列形式。The string representation of value in base toBase.

例外

toBase が 2、8、10、16 のどれでもありません。toBase is not 2, 8, 10, or 16.

次の例では、長整数配列内の各要素を、それと等価なバイナリ、16進数、10進数、16進数の文字列形式に変換します。The following example converts each element in a long integer array to its equivalent binary, hexadecimal, decimal, and hexadecimal string representations.

int[] bases = { 2, 8, 10, 16};
long[] numbers = { Int64.MinValue, -193275430, -13621, -18, 12, 
                   1914206117, Int64.MaxValue };

foreach (int baseValue in bases)
{
   Console.WriteLine("Base {0} conversion:", baseValue);
   foreach (long number in numbers)
   {
      Console.WriteLine("   {0,-23}  -->  0x{1}", 
                        number, Convert.ToString(number, baseValue));
   }
}
// The example displays the following output:
//    Base 2 conversion:
//       -9223372036854775808     -->  0x1000000000000000000000000000000000000000000000000000000000000000
//       -193275430               -->  0x1111111111111111111111111111111111110100011110101101100111011010
//       -13621                   -->  0x1111111111111111111111111111111111111111111111111100101011001011
//       -18                      -->  0x1111111111111111111111111111111111111111111111111111111111101110
//       12                       -->  0x1100
//       1914206117               -->  0x1110010000110000111011110100101
//       9223372036854775807      -->  0x111111111111111111111111111111111111111111111111111111111111111
//    Base 8 conversion:
//       -9223372036854775808     -->  0x1000000000000000000000
//       -193275430               -->  0x1777777777776436554732
//       -13621                   -->  0x1777777777777777745313
//       -18                      -->  0x1777777777777777777756
//       12                       -->  0x14
//       1914206117               -->  0x16206073645
//       9223372036854775807      -->  0x777777777777777777777
//    Base 10 conversion:
//       -9223372036854775808     -->  0x-9223372036854775808
//       -193275430               -->  0x-193275430
//       -13621                   -->  0x-13621
//       -18                      -->  0x-18
//       12                       -->  0x12
//       1914206117               -->  0x1914206117
//       9223372036854775807      -->  0x9223372036854775807
//    Base 16 conversion:
//       -9223372036854775808     -->  0x8000000000000000
//       -193275430               -->  0xfffffffff47ad9da
//       -13621                   -->  0xffffffffffffcacb
//       -18                      -->  0xffffffffffffffee
//       12                       -->  0xc
//       1914206117               -->  0x721877a5
//       9223372036854775807      -->  0x7fffffffffffffff
Dim bases() As Integer = { 2, 8, 10, 16}
Dim numbers() As Long = { Int64.MinValue, -193275430, -13621, -18, 12, _
                             1914206117, Int64.MaxValue }

For Each base As Integer In bases
   Console.WriteLine("Base {0} conversion:", base)
   For Each number As Long In numbers
      Console.WriteLine("   {0,-23}  -->  0x{1}", _
                        number, Convert.ToString(number, base))
   Next
Next
' The example displays the following output:
'    Base 2 conversion:
'       -9223372036854775808     -->  0x1000000000000000000000000000000000000000000000000000000000000000
'       -193275430               -->  0x1111111111111111111111111111111111110100011110101101100111011010
'       -13621                   -->  0x1111111111111111111111111111111111111111111111111100101011001011
'       -18                      -->  0x1111111111111111111111111111111111111111111111111111111111101110
'       12                       -->  0x1100
'       1914206117               -->  0x1110010000110000111011110100101
'       9223372036854775807      -->  0x111111111111111111111111111111111111111111111111111111111111111
'    Base 8 conversion:
'       -9223372036854775808     -->  0x1000000000000000000000
'       -193275430               -->  0x1777777777776436554732
'       -13621                   -->  0x1777777777777777745313
'       -18                      -->  0x1777777777777777777756
'       12                       -->  0x14
'       1914206117               -->  0x16206073645
'       9223372036854775807      -->  0x777777777777777777777
'    Base 10 conversion:
'       -9223372036854775808     -->  0x-9223372036854775808
'       -193275430               -->  0x-193275430
'       -13621                   -->  0x-13621
'       -18                      -->  0x-18
'       12                       -->  0x12
'       1914206117               -->  0x1914206117
'       9223372036854775807      -->  0x9223372036854775807
'    Base 16 conversion:
'       -9223372036854775808     -->  0x8000000000000000
'       -193275430               -->  0xfffffffff47ad9da
'       -13621                   -->  0xffffffffffffcacb
'       -18                      -->  0xffffffffffffffee
'       12                       -->  0xc
'       1914206117               -->  0x721877a5
'       9223372036854775807      -->  0x7fffffffffffffff
let bases = [2; 8; 10; 16]
let numbers = [ Int64.MinValue; -193275430L; -13621L; -18L; 12L; 1914206117L; Int64.MaxValue ]

for baseValue in bases do
    printfn "Base %i conversion:" baseValue
    for number in numbers do
        printfn "   % -23i  -->  0x%s" number (Convert.ToString (number, baseValue))
// The example displays the following output:
//     Base 2 conversion:
//        -9223372036854775808     -->  0x1000000000000000000000000000000000000000000000000000000000000000
//        -193275430               -->  0x1111111111111111111111111111111111110100011110101101100111011010
//        -13621                   -->  0x1111111111111111111111111111111111111111111111111100101011001011
//        -18                      -->  0x1111111111111111111111111111111111111111111111111111111111101110
//         12                      -->  0x1100
//         1914206117              -->  0x1110010000110000111011110100101
//         9223372036854775807     -->  0x111111111111111111111111111111111111111111111111111111111111111
//     Base 8 conversion:
//        -9223372036854775808     -->  0x1000000000000000000000
//        -193275430               -->  0x1777777777776436554732
//        -13621                   -->  0x1777777777777777745313
//        -18                      -->  0x1777777777777777777756
//         12                      -->  0x14
//         1914206117              -->  0x16206073645
//         9223372036854775807     -->  0x777777777777777777777
//     Base 10 conversion:
//        -9223372036854775808     -->  0x-9223372036854775808
//        -193275430               -->  0x-193275430
//        -13621                   -->  0x-13621
//        -18                      -->  0x-18
//         12                      -->  0x12
//         1914206117              -->  0x1914206117
//         9223372036854775807     -->  0x9223372036854775807
//     Base 16 conversion:
//        -9223372036854775808     -->  0x8000000000000000
//        -193275430               -->  0xfffffffff47ad9da
//        -13621                   -->  0xffffffffffffcacb
//        -18                      -->  0xffffffffffffffee
//         12                      -->  0xc
//         1914206117              -->  0x721877a5
//         9223372036854775807     -->  0x7fffffffffffffff

注釈

valuetoBase正の値で、が10でない場合、返される文字列は、符号と大きさの表現を使用します。If value is positive and toBase is not 10, the returned string uses sign-and-magnitude representation. valuetoBase負の値で10でない場合、返される文字列は2の補数表現を使用します。If value is negative and toBase is not 10, the returned string uses two's complement representation. これは、上位バイトの上位ビット (ビット 63) が符号ビットとして解釈されることを意味します。This means that the high-order bit of the highest-order byte (bit 63) is interpreted as the sign bit. 後で数値に変換する文字列を作成するためにメソッドが呼び出された場合、変換を実行するには、同様の数値表現を想定する対応するメソッドを呼び出す必要があります。ToString(Int64, Int32)If the ToString(Int64, Int32) method is called to create a string that will later be converted back to a number, a corresponding method that assumes a similar numeric representation should be called to perform the conversion. このようなConvert.ToInt64(String, Int32)メソッドInt64.Parse(String, NumberStyles)には、とが含まれます。Such methods include Convert.ToInt64(String, Int32) and Int64.Parse(String, NumberStyles).

ToString(Object, IFormatProvider)

指定したカルチャ固有の書式情報を使用して、指定したオブジェクトの値を等価の文字列形式に変換します。Converts the value of the specified object to its equivalent string representation using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(System::Object ^ value, IFormatProvider ^ provider);
public static string ToString (object value, IFormatProvider provider);
static member ToString : obj * IFormatProvider -> string
Public Shared Function ToString (value As Object, provider As IFormatProvider) As String

パラメーター

value
Object

変換する値を提供するオブジェクト、または nullAn object that supplies the value to convert, or null.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列表現。または valuenull という値を持つオブジェクトである場合は EmptyThe string representation of value, or Empty if value is an object whose value is null. valuenull の場合、メソッドは null を返します。If value is null, the method returns null.

次の例ではTemperatureObject.ToStringメソッドをオーバーライドするが、インターフェイスをIConvertible実装しないクラスを定義しています。The following example defines a Temperature class that overrides the Object.ToString method but does not implement the IConvertible interface. この例では、 Convert.ToString(Object, IFormatProvider)メソッドを呼び出して、 Temperature.ToStringメソッドを呼び出す方法を示します。The example illustrates how calls to the Convert.ToString(Object, IFormatProvider) method, in turn, call the Temperature.ToString method.

using System;

public class Temperature
{
   private decimal m_Temp;

   public Temperature(decimal temperature)
   {
      this.m_Temp = temperature;
   }
   
   public decimal Celsius
   {
      get { return this.m_Temp; }   
   }
   
   public decimal Kelvin
   {
      get { return this.m_Temp + 273.15m; }    
   }
   
   public decimal Fahrenheit
   {
      get { return Math.Round((decimal) (this.m_Temp * 9 / 5 + 32), 2); }
   }
   
   public override string ToString()
   {
      return m_Temp.ToString("N2") + " °C";
   }

}

public class Example
{
   public static void Main()
   {
      Temperature cold = new Temperature(-40);
      Temperature freezing = new Temperature(0);
      Temperature boiling = new Temperature(100);
      
      Console.WriteLine(Convert.ToString(cold, null));
      Console.WriteLine(Convert.ToString(freezing, null));
      Console.WriteLine(Convert.ToString(boiling, null));
   }
}
// The example dosplays the following output:
//       -40.00 °C
//       0.00 °C
//       100.00 °C
Public Class Temperature 
   Private m_Temp As Decimal

   Public Sub New(temperature As Decimal)
      Me.m_Temp = temperature
   End Sub
   
   Public ReadOnly Property Celsius() As Decimal
      Get
         Return Me.m_Temp
      End Get   
   End Property
   
   Public ReadOnly Property Kelvin() As Decimal
      Get
         Return Me.m_Temp + 273.15d   
      End Get
   End Property
   
   Public ReadOnly Property Fahrenheit() As Decimal
      Get
         Return Math.Round(CDec(Me.m_Temp * 9 / 5 + 32), 2)
      End Get      
   End Property
   
   Public Overrides Function ToString() As String
      Return m_Temp.ToString("N2") & " °C"
   End Function
End Class

Module Example
   Public Sub Main()
      Dim cold As New Temperature(-40)
      Dim freezing As New Temperature(0)
      Dim boiling As New Temperature(100)
      
      Console.WriteLine(Convert.ToString(cold, Nothing))
      Console.WriteLine(Convert.ToString(freezing, Nothing))
      Console.WriteLine(Convert.ToString(boiling, Nothing))
   End Sub
End Module
' The example displays the following output:
'       -40.00 °C
'       0.00 °C
'       100.00 °C

次の例ではTemperature 、インターフェイスを実装IFormattableするクラスを定義してIConvertibleいますが、インターフェイスを実装していません。The following example defines a Temperature class that implements the IFormattable interface but does not implement the IConvertible interface. この実装は、 Temperature書式指定文字列に応じて、摂氏、華氏、またはケルビンの値を表します。 IFormattable.ToStringIts IFormattable.ToString implementation represents the Temperature value in Celsius, Fahrenheit, or Kelvin, depending on the format string. また、この例でTemperatureProviderは、をIFormatProvider実装するクラスを定義し、 TemperatureクラスのIFormattable実装によって使用されるランダムに生成された書式指定文字列を提供します。The example also defines a TemperatureProvider class that implements IFormatProvider and provides a randomly generated format string that is used by the IFormattable implementation of the Temperature class.

using System;

public class Temperature : IFormattable 
{
   private decimal m_Temp; 

   public Temperature(decimal temperature)
   {
      this.m_Temp = temperature;
   } 

   public decimal Celsius 
   { get { return this.m_Temp; } } 

   public decimal Kelvin 
   { get { return this.m_Temp + 273.15m; } }   

   public decimal Fahrenheit
   {  get { return Math.Round(this.m_Temp * 9m / 5m + 32m, 2); } }

   public override String ToString() 
   { 
      return ToString("G", null); 
   } 
   
   public String ToString(String fmt, IFormatProvider provider) 
   {
      TemperatureProvider formatter = null;
      if (provider != null) 
         formatter = provider.GetFormat(typeof(TemperatureProvider)) 
                                       as TemperatureProvider;

      if (String.IsNullOrWhiteSpace(fmt)) {
         if (formatter != null) 
            fmt = formatter.Format;
         else
            fmt = "G";
      }

      switch (fmt.ToUpper()) {
         case "G":
         case "C":
            return m_Temp.ToString("N2") + " °C"; 
         case "F":
            return Fahrenheit.ToString("N2") + " °F";
         case "K":
            return Kelvin.ToString("N2") + " K";
         default:
            throw new FormatException(String.Format("'{0}' is not a valid format specifier.", fmt));
      }
   }                             
} 

public class TemperatureProvider : IFormatProvider
{
   private String[] fmtStrings = { "C", "G", "F", "K" };
   private Random rnd = new Random();
   
   public Object GetFormat(Type formatType) 
   { 
      return this; 
   }
   
   public String Format
   { get { return fmtStrings[rnd.Next(0, fmtStrings.Length)]; } }
}

public class Example
{
   public static void Main()
   {
      Temperature cold = new Temperature (-40);
      Temperature freezing = new Temperature (0);
      Temperature boiling = new Temperature (100);

      TemperatureProvider tp = new TemperatureProvider();
      
      Console.WriteLine(Convert.ToString(cold, tp));
      Console.WriteLine(Convert.ToString(freezing, tp));
      Console.WriteLine(Convert.ToString(boiling, tp));
   }
}
// The example displays output like the following:
//       -40.00 °C
//       273.15 K
//       100.00 °C
Public Class Temperature : Implements IFormattable 
   Private m_Temp As Decimal 

   Public Sub New(temperature As Decimal)
      Me.m_Temp = temperature
   End Sub 

   Public ReadOnly Property Celsius As Decimal 
      Get 
         Return Me.m_Temp
      End Get    
   End Property 

   Public ReadOnly Property Kelvin As Decimal 
      Get 
         Return Me.m_Temp + 273.15d   
      End Get 
   End Property 

   Public ReadOnly Property Fahrenheit As Decimal 
      Get 
         Return Math.Round(CDec(Me.m_Temp * 9 / 5 + 32), 2)
      End Get       
   End Property 

   Public Overrides Function ToString() As String 
      Return ToString("G", Nothing) 
   End Function 
   
   Public Overloads Function ToString(fmt As String, 
                                      provider As IFormatProvider) As String _
                             Implements IFormattable.ToString
      Dim formatter As TemperatureProvider = Nothing
      If provider IsNot Nothing Then formatter = TryCast(provider.GetFormat(GetType(TemperatureProvider)),
                                                         TemperatureProvider)

      If String.IsNullOrWhiteSpace(fmt) Then
         If formatter IsNot Nothing Then
            fmt = formatter.Format
         Else
            fmt = "G"
         End If
      End If

      Select Case fmt.ToUpper()
         Case "G", "C"
            Return m_Temp.ToString("N2") & " °C" 
         Case "F"
            Return Fahrenheit.ToString("N2") + " °F"
         Case "K"
            Return Kelvin.ToString("N2") + " K"
         Case Else
            Throw New FormatException(String.Format("'{0}' is not a valid format specifier.", fmt))
      End Select
   End Function                             
End Class 

Public Class TemperatureProvider : Implements IFormatProvider
   Private fmtStrings() As String = { "C", "G", "F", "K" }
   Private rnd As New Random()
   
   Public Function GetFormat(formatType As Type) As Object _
                   Implements IFormatProvider.GetFormat 
      Return Me 
   End Function
   
   Public ReadOnly Property Format As String
      Get
         Return fmtStrings(rnd.Next(0, fmtStrings.Length))
      End Get
   End Property
End Class

Module Example
   Public Sub Main()
      Dim cold As New Temperature(-40)
      Dim freezing As New Temperature(0)
      Dim boiling As New Temperature(100)

      Dim tp As New TemperatureProvider()
      
      Console.WriteLine(Convert.ToString(cold, tp))
      Console.WriteLine(Convert.ToString(freezing, tp))
      Console.WriteLine(Convert.ToString(boiling, tp))
   End Sub 
End Module 
' The example displays output like the following:
'       -40.00 °C
'       273.15 K
'       100.00 °C

注釈

パラメーターがvalue IConvertibleインターフェイスを実装している場合、メソッドIConvertible.ToString(IFormatProvider)はのvalue実装を呼び出します。If the value parameter implements the IConvertible interface, the method calls the IConvertible.ToString(IFormatProvider) implementation of value. それ以外の場合value 、パラメーターがIFormattableインターフェイスを実装すると、 IFormattable.ToString(String, IFormatProvider)メソッドはその実装を呼び出します。Otherwise, if the value parameter implements the IFormattable interface, the method calls its IFormattable.ToString(String, IFormatProvider) implementation. valueどちらのインターフェイスも実装していvalueない場合ToString() 、メソッドはパラメーター providerのメソッドを呼び出し、パラメーターは無視されます。If value implements neither interface, the method calls the value parameter's ToString() method, and the provider parameter is ignored.

パラメーター providerがインターフェイスまたはvalueインターフェイスを IConvertible実装している場合は、パラメーターが使用されます。IFormattableThe provider parameter is used if the value parameter implements the IConvertible or IFormattable interface. providerパラメーターを使用する最も一般的な方法は、のvalue変換で使用されるカルチャ固有の情報を指定することです。The most common use of the provider parameter is to specify culture-specific information used in the conversion of value. たとえば、 valueパラメーターが負の10進数の場合、パラメーターはprovider 、負の符号と小数点記号に使用される表記法に関するカルチャ固有の情報を指定できます。For example, if the value parameter is a negative decimal number, the provider parameter can supply culture-specific information about the notation used for the negative sign and decimal separator. 次のセクションの2番目の例は、カルチャに依存した書式設定情報を提供しない書式プロバイダーを示しています。The second example in the next section illustrates a format provider that does not supply culture-sensitive formatting information.

ToString(Single, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した単精度浮動小数点数値を等価の文字列形式に変換します。Converts the value of the specified single-precision floating-point number to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(float value, IFormatProvider ^ provider);
public static string ToString (float value, IFormatProvider provider);
static member ToString : single * IFormatProvider -> string
Public Shared Function ToString (value As Single, provider As IFormatProvider) As String

パラメーター

value
Single

変換する単精度浮動小数点数。The single-precision floating-point number to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

次の例では、値のSingle配列内の各要素を、4つの異なるカルチャの等価の文字列形式に変換します。The following example converts each element in an array of Single values to its equivalent string representation in four different cultures.

// Define an array of numbers to display.
float[] numbers = { -1.5345e16f, -123.4321f, 19092.123f, 1.1734231911290e16f };
// Define the culture names used to display them.
string[] cultureNames = { "en-US", "fr-FR", "ja-JP", "ru-RU" };

foreach (float number in numbers)
{
   Console.WriteLine("{0}:", Convert.ToString(number,
                             System.Globalization.CultureInfo.InvariantCulture));
   foreach (string cultureName in cultureNames)
   {
      System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(cultureName);
      Console.WriteLine("   {0}: {1,20}",
                        culture.Name, Convert.ToString(number, culture));
   }
   Console.WriteLine();
}   
// The example displays the following output:
//    -1.5345E+16:
//       en-US:          -1.5345E+16
//       fr-FR:          -1,5345E+16
//       ja-JP:          -1.5345E+16
//       ru-RU:          -1,5345E+16
//    
//    -123.4321:
//       en-US:            -123.4321
//       fr-FR:            -123,4321
//       ja-JP:            -123.4321
//       ru-RU:            -123,4321
//    
//    19092.123:
//       en-US:            19092.123
//       fr-FR:            19092,123
//       ja-JP:            19092.123
//       ru-RU:            19092,123
//    
//    1.173423191129E+16:
//       en-US:   1.173423191129E+16
//       fr-FR:   1,173423191129E+16
//       ja-JP:   1.173423191129E+16
//       ru-RU:   1,173423191129E+16
' Define an array of numbers to display.
Dim numbers() As Single = { -1.5345e16, -123.4321, 19092.123, _
                            1.1734231911290e16 }
' Define the culture names used to display them.
Dim cultureNames() As String = { "en-US", "fr-FR", "ja-JP", "ru-RU" }

For Each number As Single In numbers
   Console.WriteLine("{0}:", Convert.ToString(number, _
                             System.Globalization.CultureInfo.InvariantCulture))
   For Each cultureName As String In cultureNames
      Dim culture As New System.Globalization.CultureInfo(cultureName)
      Console.WriteLine("   {0}: {1,20}", _
                        culture.Name, Convert.ToString(number, culture))
   Next
   Console.WriteLine()
Next   
' The example displays the following output:
'    -1.5345E+16:
'       en-US:          -1.5345E+16
'       fr-FR:          -1,5345E+16
'       ja-JP:          -1.5345E+16
'       ru-RU:          -1,5345E+16
'    
'    -123.4321:
'       en-US:            -123.4321
'       fr-FR:            -123,4321
'       ja-JP:            -123.4321
'       ru-RU:            -123,4321
'    
'    19092.123:
'       en-US:            19092.123
'       fr-FR:            19092,123
'       ja-JP:            19092.123
'       ru-RU:            19092,123
'    
'    1.173423191129E+16:
'       en-US:   1.173423191129E+16
'       fr-FR:   1,173423191129E+16
'       ja-JP:   1.173423191129E+16
'       ru-RU:   1,173423191129E+16

注釈

この実装はとSingle.ToString(IFormatProvider)同じです。This implementation is identical to Single.ToString(IFormatProvider).

ToString(String, IFormatProvider)

指定した文字列インスタンスを返します。実際の変換は実行されません。Returns the specified string instance; no actual conversion is performed.

public:
 static System::String ^ ToString(System::String ^ value, IFormatProvider ^ provider);
public static string ToString (string value, IFormatProvider provider);
static member ToString : string * IFormatProvider -> string
Public Shared Function ToString (value As String, provider As IFormatProvider) As String

パラメーター

value
String

返される文字列。The string to return.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information. このパラメーターは無視されます。This parameter is ignored.

戻り値

value は変更されずに返されます。value is returned unchanged.

次の例ではToString 、パラメーターをString指定してメソッドを呼び出します。The following example calls the ToString method with a String parameter. メソッドは、オブジェクトをString IFormatProvider参照せずに、変更されていないを返します。The method returns the unmodified String without referencing the IFormatProvider object.

// Example of Convert::ToString( non-numeric types, IFormatProvider ).
using namespace System;
using namespace System::Globalization;

#define null (Object^)0

// An instance of this class can be passed to methods that require 
// an IFormatProvider.
ref class DummyProvider: public IFormatProvider
{
public:

   // Normally, GetFormat returns an object of the requested type
   // (usually itself) if it is able; otherwise, it returns Nothing. 
   virtual Object^ GetFormat( Type^ argType )
   {
      // Here, the type of argType is displayed, and GetFormat
      // always returns Nothing.
      Console::Write( "{0,-40}", argType->ToString() );
      return null;
   }
};

int main()
{
   // Create an instance of the IFormatProvider.
   DummyProvider^ provider = gcnew DummyProvider;
   String^ converted;

   // Convert these values using DummyProvider.
   int Int32A = -252645135;
   double DoubleA = 61680.3855;
   Object^ ObjDouble =  -98765.4321;
   DateTime DayTimeA = DateTime(2001,9,11,13,45,0);
   bool BoolA = true;
   String^ StringA = "Qwerty";
   Char CharA = '$';
   TimeSpan TSpanA = TimeSpan(0,18,0);
   Object^ ObjOther = static_cast<Object^>(provider);
   Console::WriteLine( "This example of "
   "Convert::ToString( non-numeric, IFormatProvider* ) \n"
   "generates the following output. The provider type, "
   "argument type, \nand argument value are displayed." );
   Console::WriteLine( "\nNote: The IFormatProvider object is "
   "not called for Boolean, String, \nChar, TimeSpan, "
   "and non-numeric Object." );

   // The format provider is called for these conversions.
   Console::WriteLine();
   converted = Convert::ToString( Int32A, provider );
   Console::WriteLine( "int      {0}", converted );
   converted = Convert::ToString( DoubleA, provider );
   Console::WriteLine( "double   {0}", converted );
   converted = Convert::ToString( ObjDouble, provider );
   Console::WriteLine( "Object   {0}", converted );
   converted = Convert::ToString( DayTimeA, provider );
   Console::WriteLine( "DateTime {0}", converted );

   // The format provider is not called for these conversions.
   Console::WriteLine();
   converted = Convert::ToString( BoolA, provider );
   Console::WriteLine( "bool     {0}", converted );
   converted = Convert::ToString( StringA, provider );
   Console::WriteLine( "String   {0}", converted );
   converted = Convert::ToString( CharA, provider );
   Console::WriteLine( "Char     {0}", converted );
   converted = Convert::ToString( TSpanA, provider );
   Console::WriteLine( "TimeSpan {0}", converted );
   converted = Convert::ToString( ObjOther, provider );
   Console::WriteLine( "Object   {0}", converted );
}

/*
This example of Convert::ToString( non-numeric, IFormatProvider* )
generates the following output. The provider type, argument type,
and argument value are displayed.

Note: The IFormatProvider object is not called for Boolean, String,
Char, TimeSpan, and non-numeric Object.

System.Globalization.NumberFormatInfo   int      -252645135
System.Globalization.NumberFormatInfo   double   61680.3855
System.Globalization.NumberFormatInfo   Object   -98765.4321
System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM

bool     True
String   Qwerty
Char     $
TimeSpan 00:18:00
Object   DummyProvider
*/
// Example of Convert.ToString( non-numeric types, IFormatProvider ).
using System;
using System.Globalization;

// An instance of this class can be passed to methods that require 
// an IFormatProvider.
public class DummyProvider : IFormatProvider
{
    // Normally, GetFormat returns an object of the requested type
    // (usually itself) if it is able; otherwise, it returns Nothing. 
    public object GetFormat( Type argType )
    {
        // Here, the type of argType is displayed, and GetFormat
        // always returns Nothing.
        Console.Write( "{0,-40}", argType.ToString( ) );
        return null;
    }
}

class ConvertNonNumericProviderDemo
{
    static void Main( )
    {
        // Create an instance of the IFormatProvider.
        DummyProvider provider = new DummyProvider( );
        string converted;

        // Convert these values using DummyProvider.
        int      Int32A     = -252645135;
        double   DoubleA    = 61680.3855;
        object   ObjDouble  = (object)( -98765.4321 );
        DateTime DayTimeA   = new DateTime( 2001, 9, 11, 13, 45, 0 );

        bool     BoolA      = true;
        string   StringA    = "Qwerty";
        char     CharA      = '$';
        TimeSpan TSpanA     = new TimeSpan( 0, 18, 0 );
        object   ObjOther   = (object)provider;

        Console.WriteLine( "This example of " +
            "Convert.ToString( non-numeric, IFormatProvider ) \n" +
            "generates the following output. The provider type, " +
            "argument type, \nand argument value are displayed." );
        Console.WriteLine( "\nNote: The IFormatProvider object is " +
            "not called for Boolean, String, \nChar, TimeSpan, " +
            "and non-numeric Object." );

        // The format provider is called for these conversions.
        Console.WriteLine( );
        converted = Convert.ToString( Int32A, provider );
        Console.WriteLine( "int      {0}", converted );
        converted = Convert.ToString( DoubleA, provider );
        Console.WriteLine( "double   {0}", converted );
        converted = Convert.ToString( ObjDouble, provider );
        Console.WriteLine( "object   {0}", converted );
        converted = Convert.ToString( DayTimeA, provider );
        Console.WriteLine( "DateTime {0}", converted );

        // The format provider is not called for these conversions.
        Console.WriteLine( );
        converted = Convert.ToString( BoolA, provider );
        Console.WriteLine( "bool     {0}", converted );
        converted = Convert.ToString( StringA, provider );
        Console.WriteLine( "string   {0}", converted );
        converted = Convert.ToString( CharA, provider );
        Console.WriteLine( "char     {0}", converted );
        converted = Convert.ToString( TSpanA, provider );
        Console.WriteLine( "TimeSpan {0}", converted );
        converted = Convert.ToString( ObjOther, provider );
        Console.WriteLine( "object   {0}", converted );
    }
}

/*
This example of Convert.ToString( non-numeric, IFormatProvider )
generates the following output. The provider type, argument type,
and argument value are displayed.

Note: The IFormatProvider object is not called for Boolean, String,
Char, TimeSpan, and non-numeric Object.

System.Globalization.NumberFormatInfo   int      -252645135
System.Globalization.NumberFormatInfo   double   61680.3855
System.Globalization.NumberFormatInfo   object   -98765.4321
System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM

bool     True
string   Qwerty
char     $
TimeSpan 00:18:00
object   DummyProvider

*/ 
' Example of Convert.ToString( non-numeric types, IFormatProvider ).
Imports System.Globalization

' An instance of this class can be passed to methods that require 
' an IFormatProvider.
Public Class DummyProvider
    Implements IFormatProvider

    ' Normally, GetFormat returns an object of the requested type
    ' (usually itself) if it is able; otherwise, it returns Nothing. 
    Public Function GetFormat( argType As Type ) As Object _
        Implements IFormatProvider.GetFormat

        ' Here, the type of argType is displayed, and GetFormat
        ' always returns Nothing.
        Console.Write( "{0,-40}", argType.ToString( ) )
        Return Nothing

    End Function 
End Class

Module ConvertNonNumericProviderDemo

    Sub Main( )

        ' Create an instance of the IFormatProvider.
        Dim provider    As New DummyProvider( )
        Dim converted   As String

        ' Convert these values using DummyProvider.
        Dim Int32A      As Integer  = -252645135   
        Dim DoubleA     As Double   = 61680.3855
        Dim ObjDouble   As Object   = CType( -98765.4321, Object )
        Dim DayTimeA    As DateTime = _
                            new DateTime( 2001, 9, 11, 13, 45, 0 )

        Dim BoolA       As Boolean  = True
        Dim StringA     As String   = "Qwerty"
        Dim CharA       As Char     = "$"c
        Dim TSpanA      As TimeSpan = New TimeSpan( 0, 18, 0 )
        Dim ObjOther    As Object   = CType( provider, Object )

        Console.WriteLine( "This example of " & _
            "Convert.ToString( non-numeric, IFormatProvider ) " & _
            vbCrLf & "generates the following output. The " & _
            "provider type, argument type, " & vbCrLf & "and " & _
            "argument value are displayed." )
        Console.WriteLine( vbCrLf & _
            "Note: The IFormatProvider object is not called for " & _
            "Boolean, String, " & vbCrLf & "Char, TimeSpan, " & _
            "and non-numeric Object." )

        ' The format provider is called for these conversions.
        Console.WriteLine( )
        converted =  Convert.ToString( Int32A, provider )
        Console.WriteLine( "Int32    {0}", converted )
        converted =  Convert.ToString( DoubleA, provider )
        Console.WriteLine( "Double   {0}", converted )
        converted =  Convert.ToString( ObjDouble, provider )
        Console.WriteLine( "Object   {0}", converted )
        converted =  Convert.ToString( DayTimeA, provider )
        Console.WriteLine( "DateTime {0}", converted )

        ' The format provider is not called for these conversions.
        Console.WriteLine( )
        converted =  Convert.ToString( BoolA, provider )
        Console.WriteLine( "Boolean  {0}", converted )
        converted =  Convert.ToString( StringA, provider )
        Console.WriteLine( "String   {0}", converted )
        converted =  Convert.ToString( CharA, provider )
        Console.WriteLine( "Char     {0}", converted )
        converted =  Convert.ToString( TSpanA, provider )
        Console.WriteLine( "TimeSpan {0}", converted )
        converted =  Convert.ToString( ObjOther, provider )
        Console.WriteLine( "Object   {0}", converted )

    End Sub
End Module

' This example of Convert.ToString( non-numeric, IFormatProvider )
' generates the following output. The provider type, argument type,
' and argument value are displayed.
'
' Note: The IFormatProvider object is not called for Boolean, String,
' Char, TimeSpan, and non-numeric Object.
' 
' System.Globalization.NumberFormatInfo   Int32    -252645135
' System.Globalization.NumberFormatInfo   Double   61680.3855
' System.Globalization.NumberFormatInfo   Object   -98765.4321
' System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM
' 
' Boolean  True
' String   Qwerty
' Char     $
' TimeSpan 00:18:00
' Object   DummyProvider

ToString(UInt16, IFormatProvider)

重要

この API は CLS 準拠ではありません。

指定したカルチャに固有の書式情報を使用して、指定した 16 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 16-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(System::UInt16 value, IFormatProvider ^ provider);
[System.CLSCompliant(false)]
public static string ToString (ushort value, IFormatProvider provider);
static member ToString : uint16 * IFormatProvider -> string
Public Shared Function ToString (value As UShort, provider As IFormatProvider) As String

パラメーター

value
UInt16

変換する 16 ビット符号なし整数。The 16-bit unsigned integer to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

属性

次の例では、 NumberFormatInfo負の符号を文字列 "~"、正の符号を文字列 "!" として定義するカスタムクラスを定義しています。The following example defines a custom NumberFormatInfo class that defines its negative sign as the string "~" and its positive sign as the string "!". 次に、 ToString(UInt16, IFormatProvider)メソッドを呼び出して、16ビット符号なし整数値を等価の文字列形式に変換します。It then calls the ToString(UInt16, IFormatProvider) method to convert a 16-bit unsigned integer value to its equivalent string representation. 変換では、インバリアントカルチャとカスタムNumberFormatInfoオブジェクトの両方が使用されます。The conversion uses both the invariant culture and the custom NumberFormatInfo object. 出力は、この書式設定情報が使用されていないことを示します。既定では、"G" 書式指定子に正の値を持つ正の符号が含まれていないためです。The output indicates that this formatting information is not used, because by default the "G" format specifier does not include a positive sign with positive values.

ushort number = UInt16.MaxValue;
System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
nfi.NegativeSign = "~";
nfi.PositiveSign = "!";

Console.WriteLine("{0,-6}  -->  {1,6}",
                  Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture),
                  Convert.ToString(number, nfi));
// The example displays the following output:
//       65535   -->   65535
Dim number As UShort = UInt16.MaxValue
Dim nfi As New System.Globalization.NumberFormatInfo()
nfi.NegativeSign = "~"
nfi.PositiveSign = "!"

Console.WriteLine("{0,-6}  -->  {1,6}", _
                  Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture), _
                  Convert.ToString(number, nfi))
' The example displays the following output:
'       65535   -->   65535

注釈

この実装はとUInt16.ToString(IFormatProvider)同じです。This implementation is identical to UInt16.ToString(IFormatProvider).

ToString(UInt32, IFormatProvider)

重要

この API は CLS 準拠ではありません。

指定したカルチャに固有の書式情報を使用して、指定した 32 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 32-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(System::UInt32 value, IFormatProvider ^ provider);
[System.CLSCompliant(false)]
public static string ToString (uint value, IFormatProvider provider);
static member ToString : uint32 * IFormatProvider -> string
Public Shared Function ToString (value As UInteger, provider As IFormatProvider) As String

パラメーター

value
UInt32

変換する 32 ビット符号なし整数。The 32-bit unsigned integer to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

属性

次の例では、 NumberFormatInfo負の符号を文字列 "~"、正の符号を文字列 "!" として定義するカスタムクラスを定義しています。The following example defines a custom NumberFormatInfo class that defines its negative sign as the string "~" and its positive sign as the string "!". 次に、 ToString(UInt32, IFormatProvider)メソッドを呼び出して、符号なし整数値を等価の文字列形式に変換します。It then calls the ToString(UInt32, IFormatProvider) method to convert an unsigned integer value to its equivalent string representation. 変換では、インバリアントカルチャとカスタムNumberFormatInfoオブジェクトの両方が使用されます。The conversion uses both the invariant culture and the custom NumberFormatInfo object. 出力は、この書式設定情報が使用されていないことを示します。既定では、"G" 書式指定子に正の値を持つ正の符号が含まれていないためです。The output indicates that this formatting information is not used, because by default the "G" format specifier does not include a positive sign with positive values.

uint number = UInt32.MaxValue;
System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
nfi.NegativeSign = "~";
nfi.PositiveSign = "!";

Console.WriteLine("{0,-8}  -->  {1,8}",
                  Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture),
                  Convert.ToString(number, nfi));
// The example displays the following output:
//       4294967295  -->  4294967295
Dim number As UInteger = UInt32.MaxValue
Dim nfi As New System.Globalization.NumberFormatInfo()
nfi.NegativeSign = "~"
nfi.PositiveSign = "!"

Console.WriteLine("{0,-8}  -->  {1,8}", _
                  Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture), _
                  Convert.ToString(number, nfi))
' The example displays the following output:
'       4294967295  -->  4294967295

注釈

この実装はとUInt32.ToString(IFormatProvider)同じです。This implementation is identical to UInt32.ToString(IFormatProvider).

ToString(Char, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した Unicode 文字の値を等価の文字列形式に変換します。Converts the value of the specified Unicode character to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(char value, IFormatProvider ^ provider);
public static string ToString (char value, IFormatProvider provider);
static member ToString : char * IFormatProvider -> string
Public Shared Function ToString (value As Char, provider As IFormatProvider) As String

パラメーター

value
Char

変換する Unicode 文字。The Unicode character to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information. このパラメーターは無視されます。This parameter is ignored.

戻り値

value の文字列形式。The string representation of value.

次の例ではCharToStringメソッドをString使用して値をにIFormatProvider変換します。このオブジェクトは、呼び出し元の書式プロバイダーの型を表示するオブジェクトを使用しています。The following example converts a Char value to a String with the ToString method, using an IFormatProvider object that displays the type of the format provider for which it is called. この例は、 IFormatProviderオブジェクトが参照されていないことを示しています。The example shows that the IFormatProvider object is not referenced.

// Example of Convert::ToString( non-numeric types, IFormatProvider ).
using namespace System;
using namespace System::Globalization;

#define null (Object^)0

// An instance of this class can be passed to methods that require 
// an IFormatProvider.
ref class DummyProvider: public IFormatProvider
{
public:

   // Normally, GetFormat returns an object of the requested type
   // (usually itself) if it is able; otherwise, it returns Nothing. 
   virtual Object^ GetFormat( Type^ argType )
   {
      // Here, the type of argType is displayed, and GetFormat
      // always returns Nothing.
      Console::Write( "{0,-40}", argType->ToString() );
      return null;
   }
};

int main()
{
   // Create an instance of the IFormatProvider.
   DummyProvider^ provider = gcnew DummyProvider;
   String^ converted;

   // Convert these values using DummyProvider.
   int Int32A = -252645135;
   double DoubleA = 61680.3855;
   Object^ ObjDouble =  -98765.4321;
   DateTime DayTimeA = DateTime(2001,9,11,13,45,0);
   bool BoolA = true;
   String^ StringA = "Qwerty";
   Char CharA = '$';
   TimeSpan TSpanA = TimeSpan(0,18,0);
   Object^ ObjOther = static_cast<Object^>(provider);
   Console::WriteLine( "This example of "
   "Convert::ToString( non-numeric, IFormatProvider* ) \n"
   "generates the following output. The provider type, "
   "argument type, \nand argument value are displayed." );
   Console::WriteLine( "\nNote: The IFormatProvider object is "
   "not called for Boolean, String, \nChar, TimeSpan, "
   "and non-numeric Object." );

   // The format provider is called for these conversions.
   Console::WriteLine();
   converted = Convert::ToString( Int32A, provider );
   Console::WriteLine( "int      {0}", converted );
   converted = Convert::ToString( DoubleA, provider );
   Console::WriteLine( "double   {0}", converted );
   converted = Convert::ToString( ObjDouble, provider );
   Console::WriteLine( "Object   {0}", converted );
   converted = Convert::ToString( DayTimeA, provider );
   Console::WriteLine( "DateTime {0}", converted );

   // The format provider is not called for these conversions.
   Console::WriteLine();
   converted = Convert::ToString( BoolA, provider );
   Console::WriteLine( "bool     {0}", converted );
   converted = Convert::ToString( StringA, provider );
   Console::WriteLine( "String   {0}", converted );
   converted = Convert::ToString( CharA, provider );
   Console::WriteLine( "Char     {0}", converted );
   converted = Convert::ToString( TSpanA, provider );
   Console::WriteLine( "TimeSpan {0}", converted );
   converted = Convert::ToString( ObjOther, provider );
   Console::WriteLine( "Object   {0}", converted );
}

/*
This example of Convert::ToString( non-numeric, IFormatProvider* )
generates the following output. The provider type, argument type,
and argument value are displayed.

Note: The IFormatProvider object is not called for Boolean, String,
Char, TimeSpan, and non-numeric Object.

System.Globalization.NumberFormatInfo   int      -252645135
System.Globalization.NumberFormatInfo   double   61680.3855
System.Globalization.NumberFormatInfo   Object   -98765.4321
System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM

bool     True
String   Qwerty
Char     $
TimeSpan 00:18:00
Object   DummyProvider
*/
// Example of Convert.ToString( non-numeric types, IFormatProvider ).
using System;
using System.Globalization;

// An instance of this class can be passed to methods that require 
// an IFormatProvider.
public class DummyProvider : IFormatProvider
{
    // Normally, GetFormat returns an object of the requested type
    // (usually itself) if it is able; otherwise, it returns Nothing. 
    public object GetFormat( Type argType )
    {
        // Here, the type of argType is displayed, and GetFormat
        // always returns Nothing.
        Console.Write( "{0,-40}", argType.ToString( ) );
        return null;
    }
}

class ConvertNonNumericProviderDemo
{
    static void Main( )
    {
        // Create an instance of the IFormatProvider.
        DummyProvider provider = new DummyProvider( );
        string converted;

        // Convert these values using DummyProvider.
        int      Int32A     = -252645135;
        double   DoubleA    = 61680.3855;
        object   ObjDouble  = (object)( -98765.4321 );
        DateTime DayTimeA   = new DateTime( 2001, 9, 11, 13, 45, 0 );

        bool     BoolA      = true;
        string   StringA    = "Qwerty";
        char     CharA      = '$';
        TimeSpan TSpanA     = new TimeSpan( 0, 18, 0 );
        object   ObjOther   = (object)provider;

        Console.WriteLine( "This example of " +
            "Convert.ToString( non-numeric, IFormatProvider ) \n" +
            "generates the following output. The provider type, " +
            "argument type, \nand argument value are displayed." );
        Console.WriteLine( "\nNote: The IFormatProvider object is " +
            "not called for Boolean, String, \nChar, TimeSpan, " +
            "and non-numeric Object." );

        // The format provider is called for these conversions.
        Console.WriteLine( );
        converted = Convert.ToString( Int32A, provider );
        Console.WriteLine( "int      {0}", converted );
        converted = Convert.ToString( DoubleA, provider );
        Console.WriteLine( "double   {0}", converted );
        converted = Convert.ToString( ObjDouble, provider );
        Console.WriteLine( "object   {0}", converted );
        converted = Convert.ToString( DayTimeA, provider );
        Console.WriteLine( "DateTime {0}", converted );

        // The format provider is not called for these conversions.
        Console.WriteLine( );
        converted = Convert.ToString( BoolA, provider );
        Console.WriteLine( "bool     {0}", converted );
        converted = Convert.ToString( StringA, provider );
        Console.WriteLine( "string   {0}", converted );
        converted = Convert.ToString( CharA, provider );
        Console.WriteLine( "char     {0}", converted );
        converted = Convert.ToString( TSpanA, provider );
        Console.WriteLine( "TimeSpan {0}", converted );
        converted = Convert.ToString( ObjOther, provider );
        Console.WriteLine( "object   {0}", converted );
    }
}

/*
This example of Convert.ToString( non-numeric, IFormatProvider )
generates the following output. The provider type, argument type,
and argument value are displayed.

Note: The IFormatProvider object is not called for Boolean, String,
Char, TimeSpan, and non-numeric Object.

System.Globalization.NumberFormatInfo   int      -252645135
System.Globalization.NumberFormatInfo   double   61680.3855
System.Globalization.NumberFormatInfo   object   -98765.4321
System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM

bool     True
string   Qwerty
char     $
TimeSpan 00:18:00
object   DummyProvider

*/ 
' Example of Convert.ToString( non-numeric types, IFormatProvider ).
Imports System.Globalization

' An instance of this class can be passed to methods that require 
' an IFormatProvider.
Public Class DummyProvider
    Implements IFormatProvider

    ' Normally, GetFormat returns an object of the requested type
    ' (usually itself) if it is able; otherwise, it returns Nothing. 
    Public Function GetFormat( argType As Type ) As Object _
        Implements IFormatProvider.GetFormat

        ' Here, the type of argType is displayed, and GetFormat
        ' always returns Nothing.
        Console.Write( "{0,-40}", argType.ToString( ) )
        Return Nothing

    End Function 
End Class

Module ConvertNonNumericProviderDemo

    Sub Main( )

        ' Create an instance of the IFormatProvider.
        Dim provider    As New DummyProvider( )
        Dim converted   As String

        ' Convert these values using DummyProvider.
        Dim Int32A      As Integer  = -252645135   
        Dim DoubleA     As Double   = 61680.3855
        Dim ObjDouble   As Object   = CType( -98765.4321, Object )
        Dim DayTimeA    As DateTime = _
                            new DateTime( 2001, 9, 11, 13, 45, 0 )

        Dim BoolA       As Boolean  = True
        Dim StringA     As String   = "Qwerty"
        Dim CharA       As Char     = "$"c
        Dim TSpanA      As TimeSpan = New TimeSpan( 0, 18, 0 )
        Dim ObjOther    As Object   = CType( provider, Object )

        Console.WriteLine( "This example of " & _
            "Convert.ToString( non-numeric, IFormatProvider ) " & _
            vbCrLf & "generates the following output. The " & _
            "provider type, argument type, " & vbCrLf & "and " & _
            "argument value are displayed." )
        Console.WriteLine( vbCrLf & _
            "Note: The IFormatProvider object is not called for " & _
            "Boolean, String, " & vbCrLf & "Char, TimeSpan, " & _
            "and non-numeric Object." )

        ' The format provider is called for these conversions.
        Console.WriteLine( )
        converted =  Convert.ToString( Int32A, provider )
        Console.WriteLine( "Int32    {0}", converted )
        converted =  Convert.ToString( DoubleA, provider )
        Console.WriteLine( "Double   {0}", converted )
        converted =  Convert.ToString( ObjDouble, provider )
        Console.WriteLine( "Object   {0}", converted )
        converted =  Convert.ToString( DayTimeA, provider )
        Console.WriteLine( "DateTime {0}", converted )

        ' The format provider is not called for these conversions.
        Console.WriteLine( )
        converted =  Convert.ToString( BoolA, provider )
        Console.WriteLine( "Boolean  {0}", converted )
        converted =  Convert.ToString( StringA, provider )
        Console.WriteLine( "String   {0}", converted )
        converted =  Convert.ToString( CharA, provider )
        Console.WriteLine( "Char     {0}", converted )
        converted =  Convert.ToString( TSpanA, provider )
        Console.WriteLine( "TimeSpan {0}", converted )
        converted =  Convert.ToString( ObjOther, provider )
        Console.WriteLine( "Object   {0}", converted )

    End Sub
End Module

' This example of Convert.ToString( non-numeric, IFormatProvider )
' generates the following output. The provider type, argument type,
' and argument value are displayed.
'
' Note: The IFormatProvider object is not called for Boolean, String,
' Char, TimeSpan, and non-numeric Object.
' 
' System.Globalization.NumberFormatInfo   Int32    -252645135
' System.Globalization.NumberFormatInfo   Double   61680.3855
' System.Globalization.NumberFormatInfo   Object   -98765.4321
' System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM
' 
' Boolean  True
' String   Qwerty
' Char     $
' TimeSpan 00:18:00
' Object   DummyProvider

注釈

この実装はとChar.ToString()同じです。This implementation is identical to Char.ToString(). providerパラメーターは無視されます。The provider parameter is ignored.

ToString(Int64, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 64 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 64-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(long value, IFormatProvider ^ provider);
public static string ToString (long value, IFormatProvider provider);
static member ToString : int64 * IFormatProvider -> string
Public Shared Function ToString (value As Long, provider As IFormatProvider) As String

パラメーター

value
Int64

変換する 64 ビット符号付き整数。The 64-bit signed integer to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

次の例では、 NumberFormatInfo負の符号を文字列 "~"、正の符号を文字列 "!" として定義するカスタムクラスを定義しています。The following example defines a custom NumberFormatInfo class that defines its negative sign as the string "~" and its positive sign as the string "!". 次に、 ToString(Int64, IFormatProvider)メソッドを呼び出して、長整数配列内の各要素を等価の文字列形式に変換します。It then calls the ToString(Int64, IFormatProvider) method to convert each element in a long integer array to its equivalent string representation. 変換では、カスタムNumberFormatInfoオブジェクトだけでなく、インバリアントカルチャも使用します。The conversion uses the invariant culture as well as the custom NumberFormatInfo object.

long[] numbers = { ((long) Int32.MinValue) * 2, ((long) Int32.MaxValue) * 2};
System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
nfi.NegativeSign = "~";
nfi.PositiveSign = "!";

foreach (long number in numbers)
   Console.WriteLine("{0,-12}  -->  {1,12}", 
                     Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture), 
                     Convert.ToString(number, nfi));
// The example displays the following output:
//       -4294967296  -->  ~4294967296
//       4294967294  -->  4294967294
Dim numbers() As Long = { CLng(Int32.MinValue) * 2, CLng(Int32.MaxValue) * 2 }
Dim nfi As New System.Globalization.NumberFormatInfo()
nfi.NegativeSign = "~"
nfi.PositiveSign = "!"

For Each number As Long In numbers
   Console.WriteLine("{0,-12}  -->  {1,12}", _
                     Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture), _
                     Convert.ToString(number, nfi))
Next
' The example displays the following output:
'       -4294967296  -->  ~4294967296
'       4294967294   -->  4294967294

注釈

この実装はとInt64.ToString(IFormatProvider)同じです。This implementation is identical to Int64.ToString(IFormatProvider).

ToString(Byte, Int32)

8 ビット符号なし整数値を、指定した基数で表される等価な文字列形式に変換します。Converts the value of an 8-bit unsigned integer to its equivalent string representation in a specified base.

public:
 static System::String ^ ToString(System::Byte value, int toBase);
public static string ToString (byte value, int toBase);
static member ToString : byte * int -> string
Public Shared Function ToString (value As Byte, toBase As Integer) As String

パラメーター

value
Byte

変換する 8 ビット符号なし整数。The 8-bit unsigned integer to convert.

toBase
Int32

戻り値の基数。これは 2、8、10、16 である必要があります。The base of the return value, which must be 2, 8, 10, or 16.

戻り値

基数 valuetoBase の文字列形式。The string representation of value in base toBase.

例外

toBase が 2、8、10、16 のどれでもありません。toBase is not 2, 8, 10, or 16.

次の例では、バイト配列の各要素を、それと等価なバイナリ、16進数、10進数、16進数の文字列形式に変換します。The following example converts each element in a byte array to its equivalent binary, hexadecimal, decimal, and hexadecimal string representations.

int[] bases = { 2, 8, 10, 16};
byte[] numbers = { Byte.MinValue, 12, 103, Byte.MaxValue};

foreach (int baseValue in bases)
{
   Console.WriteLine("Base {0} conversion:", baseValue);
   foreach (byte number in numbers)
   {
      Console.WriteLine("   {0,-5}  -->  0x{1}", 
                        number, Convert.ToString(number, baseValue));
   }
}
// The example displays the following output:
//       Base 2 conversion:
//          0      -->  0x0
//          12     -->  0x1100
//          103    -->  0x1100111
//          255    -->  0x11111111
//       Base 8 conversion:
//          0      -->  0x0
//          12     -->  0x14
//          103    -->  0x147
//          255    -->  0x377
//       Base 10 conversion:
//          0      -->  0x0
//          12     -->  0x12
//          103    -->  0x103
//          255    -->  0x255
//       Base 16 conversion:
//          0      -->  0x0
//          12     -->  0xc
//          103    -->  0x67
//          255    -->  0xff
Dim bases() As Integer = { 2, 8, 10, 16}
Dim numbers() As Byte = { Byte.MinValue, 12, 103, Byte.MaxValue}

For Each base As Integer In bases
   Console.WriteLine("Base {0} conversion:", base)
   For Each number As Byte In numbers
      Console.WriteLine("   {0,-5}  -->  0x{1}", _
                        number, Convert.ToString(number, base))
   Next
Next
' The example displays the following output:
'       Base 2 conversion:
'          0      -->  0x0
'          12     -->  0x1100
'          103    -->  0x1100111
'          255    -->  0x11111111
'       Base 8 conversion:
'          0      -->  0x0
'          12     -->  0x14
'          103    -->  0x147
'          255    -->  0x377
'       Base 10 conversion:
'          0      -->  0x0
'          12     -->  0x12
'          103    -->  0x103
'          255    -->  0x255
'       Base 16 conversion:
'          0      -->  0x0
'          12     -->  0xc
'          103    -->  0x67
'          255    -->  0xff
let bases = [2; 8; 10; 16]
let numbers = [ Byte.MinValue; 12uy; 103uy; Byte.MaxValue ]

for baseValue in bases do
    printfn "Base %i conversion:" baseValue
    for number in numbers do
        printfn "   % -5i  -->  0x%s" number (Convert.ToString (number, baseValue))
// The example displays the following output:
//     Base 2 conversion:
//         0     -->  0x0
//         12    -->  0x1100
//         103   -->  0x1100111
//         255   -->  0x11111111
//     Base 8 conversion:
//         0     -->  0x0
//         12    -->  0x14
//         103   -->  0x147
//         255   -->  0x377
//     Base 10 conversion:
//         0     -->  0x0
//         12    -->  0x12
//         103   -->  0x103
//         255   -->  0x255
//     Base 16 conversion:
//         0     -->  0x0
//         12    -->  0xc
//         103   -->  0x67
//         255   -->  0xff

注釈

toBase 10 に等しくない場合、 Convert.ToString(Byte, Int32)メソッドによって返される文字列はvalue 、その大きさだけで表されます。If toBase does not equal 10, the string that is returned by the Convert.ToString(Byte, Int32) method represents value by its magnitude only. 後で数値に変換する文字列を作成するためにメソッドが呼び出された場合、変換を実行するには、大きさのみの数値表現を想定する対応するメソッドを呼び出す必要があります。If the method is called to create a string that will later be converted back to a number, a corresponding method that assumes a magnitude-only numeric representation should be called to perform the conversion. このようなConvert.ToByte(String, Int32)メソッドByte.Parse(String, NumberStyles)には、やなどがあります。Such methods include Convert.ToByte(String, Int32) or Byte.Parse(String, NumberStyles).

ToString(UInt64)

重要

この API は CLS 準拠ではありません。

指定した 64 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 64-bit unsigned integer to its equivalent string representation.

public:
 static System::String ^ ToString(System::UInt64 value);
[System.CLSCompliant(false)]
public static string ToString (ulong value);
static member ToString : uint64 -> string
Public Shared Function ToString (value As ULong) As String

パラメーター

value
UInt64

変換する 64 ビット符号なし整数。The 64-bit unsigned integer to convert.

戻り値

value の文字列形式。The string representation of value.

属性

次の例では、符号なし長整数配列内の各要素を、それと等価な文字列形式に変換します。The following example converts each element in an unsigned long integer array to its equivalent string representation.

ulong[] numbers = { UInt64.MinValue, 1031, 189045, UInt64.MaxValue };
string result;

foreach (ulong number in numbers)
{
   result = Convert.ToString(number);
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                        number.GetType().Name, number,
                        result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the UInt64 value 0 to the String value 0.
//    Converted the UInt64 value 1031 to the String value 1031.
//    Converted the UInt64 value 189045 to the String value 189045.
//    Converted the UInt64 value 18446744073709551615 to the String value 18446744073709551615.
Dim numbers() As ULong = { UInt64.MinValue, 1031, 189045, UInt64.MaxValue }
Dim result As String

For Each number As ULong In numbers
   result = Convert.ToString(number)
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.", _
                        number.GetType().Name, number, _
                        result.GetType().Name, result)
Next
' The example displays the following output:
'    Converted the UInt64 value 0 to the String value 0.
'    Converted the UInt64 value 1031 to the String value 1031.
'    Converted the UInt64 value 189045 to the String value 189045.
'    Converted the UInt64 value 18446744073709551615 to the String value 18446744073709551615.

注釈

この実装はとUInt64.ToString()同じです。This implementation is identical to UInt64.ToString().

ToString(Boolean, IFormatProvider)

指定したブール値を、それと等しい文字列形式に変換します。Converts the specified Boolean value to its equivalent string representation.

public:
 static System::String ^ ToString(bool value, IFormatProvider ^ provider);
public static string ToString (bool value, IFormatProvider provider);
static member ToString : bool * IFormatProvider -> string
Public Shared Function ToString (value As Boolean, provider As IFormatProvider) As String

パラメーター

value
Boolean

変換するブール値。The Boolean value to convert.

provider
IFormatProvider

オブジェクトのインスタンス。An instance of an object. このパラメーターは無視されます。This parameter is ignored.

戻り値

value の文字列形式。The string representation of value.

次の例ではBooleanToStringメソッドをString使用して値をにIFormatProvider変換します。このオブジェクトは、呼び出し元の書式プロバイダーの型を表示するオブジェクトを使用しています。The following example converts a Boolean value to a String with the ToString method, using an IFormatProvider object that displays the type of the format provider for which it is called. この例は、 IFormatProviderオブジェクトが参照されていないことを示しています。The example shows that the IFormatProvider object is not referenced.

// Example of Convert::ToString( non-numeric types, IFormatProvider ).
using namespace System;
using namespace System::Globalization;

#define null (Object^)0

// An instance of this class can be passed to methods that require 
// an IFormatProvider.
ref class DummyProvider: public IFormatProvider
{
public:

   // Normally, GetFormat returns an object of the requested type
   // (usually itself) if it is able; otherwise, it returns Nothing. 
   virtual Object^ GetFormat( Type^ argType )
   {
      // Here, the type of argType is displayed, and GetFormat
      // always returns Nothing.
      Console::Write( "{0,-40}", argType->ToString() );
      return null;
   }
};

int main()
{
   // Create an instance of the IFormatProvider.
   DummyProvider^ provider = gcnew DummyProvider;
   String^ converted;

   // Convert these values using DummyProvider.
   int Int32A = -252645135;
   double DoubleA = 61680.3855;
   Object^ ObjDouble =  -98765.4321;
   DateTime DayTimeA = DateTime(2001,9,11,13,45,0);
   bool BoolA = true;
   String^ StringA = "Qwerty";
   Char CharA = '$';
   TimeSpan TSpanA = TimeSpan(0,18,0);
   Object^ ObjOther = static_cast<Object^>(provider);
   Console::WriteLine( "This example of "
   "Convert::ToString( non-numeric, IFormatProvider* ) \n"
   "generates the following output. The provider type, "
   "argument type, \nand argument value are displayed." );
   Console::WriteLine( "\nNote: The IFormatProvider object is "
   "not called for Boolean, String, \nChar, TimeSpan, "
   "and non-numeric Object." );

   // The format provider is called for these conversions.
   Console::WriteLine();
   converted = Convert::ToString( Int32A, provider );
   Console::WriteLine( "int      {0}", converted );
   converted = Convert::ToString( DoubleA, provider );
   Console::WriteLine( "double   {0}", converted );
   converted = Convert::ToString( ObjDouble, provider );
   Console::WriteLine( "Object   {0}", converted );
   converted = Convert::ToString( DayTimeA, provider );
   Console::WriteLine( "DateTime {0}", converted );

   // The format provider is not called for these conversions.
   Console::WriteLine();
   converted = Convert::ToString( BoolA, provider );
   Console::WriteLine( "bool     {0}", converted );
   converted = Convert::ToString( StringA, provider );
   Console::WriteLine( "String   {0}", converted );
   converted = Convert::ToString( CharA, provider );
   Console::WriteLine( "Char     {0}", converted );
   converted = Convert::ToString( TSpanA, provider );
   Console::WriteLine( "TimeSpan {0}", converted );
   converted = Convert::ToString( ObjOther, provider );
   Console::WriteLine( "Object   {0}", converted );
}

/*
This example of Convert::ToString( non-numeric, IFormatProvider* )
generates the following output. The provider type, argument type,
and argument value are displayed.

Note: The IFormatProvider object is not called for Boolean, String,
Char, TimeSpan, and non-numeric Object.

System.Globalization.NumberFormatInfo   int      -252645135
System.Globalization.NumberFormatInfo   double   61680.3855
System.Globalization.NumberFormatInfo   Object   -98765.4321
System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM

bool     True
String   Qwerty
Char     $
TimeSpan 00:18:00
Object   DummyProvider
*/
// Example of Convert.ToString( non-numeric types, IFormatProvider ).
using System;
using System.Globalization;

// An instance of this class can be passed to methods that require 
// an IFormatProvider.
public class DummyProvider : IFormatProvider
{
    // Normally, GetFormat returns an object of the requested type
    // (usually itself) if it is able; otherwise, it returns Nothing. 
    public object GetFormat( Type argType )
    {
        // Here, the type of argType is displayed, and GetFormat
        // always returns Nothing.
        Console.Write( "{0,-40}", argType.ToString( ) );
        return null;
    }
}

class ConvertNonNumericProviderDemo
{
    static void Main( )
    {
        // Create an instance of the IFormatProvider.
        DummyProvider provider = new DummyProvider( );
        string converted;

        // Convert these values using DummyProvider.
        int      Int32A     = -252645135;
        double   DoubleA    = 61680.3855;
        object   ObjDouble  = (object)( -98765.4321 );
        DateTime DayTimeA   = new DateTime( 2001, 9, 11, 13, 45, 0 );

        bool     BoolA      = true;
        string   StringA    = "Qwerty";
        char     CharA      = '$';
        TimeSpan TSpanA     = new TimeSpan( 0, 18, 0 );
        object   ObjOther   = (object)provider;

        Console.WriteLine( "This example of " +
            "Convert.ToString( non-numeric, IFormatProvider ) \n" +
            "generates the following output. The provider type, " +
            "argument type, \nand argument value are displayed." );
        Console.WriteLine( "\nNote: The IFormatProvider object is " +
            "not called for Boolean, String, \nChar, TimeSpan, " +
            "and non-numeric Object." );

        // The format provider is called for these conversions.
        Console.WriteLine( );
        converted = Convert.ToString( Int32A, provider );
        Console.WriteLine( "int      {0}", converted );
        converted = Convert.ToString( DoubleA, provider );
        Console.WriteLine( "double   {0}", converted );
        converted = Convert.ToString( ObjDouble, provider );
        Console.WriteLine( "object   {0}", converted );
        converted = Convert.ToString( DayTimeA, provider );
        Console.WriteLine( "DateTime {0}", converted );

        // The format provider is not called for these conversions.
        Console.WriteLine( );
        converted = Convert.ToString( BoolA, provider );
        Console.WriteLine( "bool     {0}", converted );
        converted = Convert.ToString( StringA, provider );
        Console.WriteLine( "string   {0}", converted );
        converted = Convert.ToString( CharA, provider );
        Console.WriteLine( "char     {0}", converted );
        converted = Convert.ToString( TSpanA, provider );
        Console.WriteLine( "TimeSpan {0}", converted );
        converted = Convert.ToString( ObjOther, provider );
        Console.WriteLine( "object   {0}", converted );
    }
}

/*
This example of Convert.ToString( non-numeric, IFormatProvider )
generates the following output. The provider type, argument type,
and argument value are displayed.

Note: The IFormatProvider object is not called for Boolean, String,
Char, TimeSpan, and non-numeric Object.

System.Globalization.NumberFormatInfo   int      -252645135
System.Globalization.NumberFormatInfo   double   61680.3855
System.Globalization.NumberFormatInfo   object   -98765.4321
System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM

bool     True
string   Qwerty
char     $
TimeSpan 00:18:00
object   DummyProvider

*/ 
' Example of Convert.ToString( non-numeric types, IFormatProvider ).
Imports System.Globalization

' An instance of this class can be passed to methods that require 
' an IFormatProvider.
Public Class DummyProvider
    Implements IFormatProvider

    ' Normally, GetFormat returns an object of the requested type
    ' (usually itself) if it is able; otherwise, it returns Nothing. 
    Public Function GetFormat( argType As Type ) As Object _
        Implements IFormatProvider.GetFormat

        ' Here, the type of argType is displayed, and GetFormat
        ' always returns Nothing.
        Console.Write( "{0,-40}", argType.ToString( ) )
        Return Nothing

    End Function 
End Class

Module ConvertNonNumericProviderDemo

    Sub Main( )

        ' Create an instance of the IFormatProvider.
        Dim provider    As New DummyProvider( )
        Dim converted   As String

        ' Convert these values using DummyProvider.
        Dim Int32A      As Integer  = -252645135   
        Dim DoubleA     As Double   = 61680.3855
        Dim ObjDouble   As Object   = CType( -98765.4321, Object )
        Dim DayTimeA    As DateTime = _
                            new DateTime( 2001, 9, 11, 13, 45, 0 )

        Dim BoolA       As Boolean  = True
        Dim StringA     As String   = "Qwerty"
        Dim CharA       As Char     = "$"c
        Dim TSpanA      As TimeSpan = New TimeSpan( 0, 18, 0 )
        Dim ObjOther    As Object   = CType( provider, Object )

        Console.WriteLine( "This example of " & _
            "Convert.ToString( non-numeric, IFormatProvider ) " & _
            vbCrLf & "generates the following output. The " & _
            "provider type, argument type, " & vbCrLf & "and " & _
            "argument value are displayed." )
        Console.WriteLine( vbCrLf & _
            "Note: The IFormatProvider object is not called for " & _
            "Boolean, String, " & vbCrLf & "Char, TimeSpan, " & _
            "and non-numeric Object." )

        ' The format provider is called for these conversions.
        Console.WriteLine( )
        converted =  Convert.ToString( Int32A, provider )
        Console.WriteLine( "Int32    {0}", converted )
        converted =  Convert.ToString( DoubleA, provider )
        Console.WriteLine( "Double   {0}", converted )
        converted =  Convert.ToString( ObjDouble, provider )
        Console.WriteLine( "Object   {0}", converted )
        converted =  Convert.ToString( DayTimeA, provider )
        Console.WriteLine( "DateTime {0}", converted )

        ' The format provider is not called for these conversions.
        Console.WriteLine( )
        converted =  Convert.ToString( BoolA, provider )
        Console.WriteLine( "Boolean  {0}", converted )
        converted =  Convert.ToString( StringA, provider )
        Console.WriteLine( "String   {0}", converted )
        converted =  Convert.ToString( CharA, provider )
        Console.WriteLine( "Char     {0}", converted )
        converted =  Convert.ToString( TSpanA, provider )
        Console.WriteLine( "TimeSpan {0}", converted )
        converted =  Convert.ToString( ObjOther, provider )
        Console.WriteLine( "Object   {0}", converted )

    End Sub
End Module

' This example of Convert.ToString( non-numeric, IFormatProvider )
' generates the following output. The provider type, argument type,
' and argument value are displayed.
'
' Note: The IFormatProvider object is not called for Boolean, String,
' Char, TimeSpan, and non-numeric Object.
' 
' System.Globalization.NumberFormatInfo   Int32    -252645135
' System.Globalization.NumberFormatInfo   Double   61680.3855
' System.Globalization.NumberFormatInfo   Object   -98765.4321
' System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM
' 
' Boolean  True
' String   Qwerty
' Char     $
' TimeSpan 00:18:00
' Object   DummyProvider

注釈

この実装はとBoolean.ToString同じです。This implementation is identical to Boolean.ToString. 値とBoolean.TrueString true 値にfalse対してを返します。 Boolean.FalseStringIt returns Boolean.TrueString for true values and Boolean.FalseString for false values.

ToString(Byte, IFormatProvider)

指定したカルチャに固有の書式情報を使用して、指定した 8 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 8-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

public:
 static System::String ^ ToString(System::Byte value, IFormatProvider ^ provider);
public static string ToString (byte value, IFormatProvider provider);
static member ToString : byte * IFormatProvider -> string
Public Shared Function ToString (value As Byte, provider As IFormatProvider) As String

パラメーター

value
Byte

変換する 8 ビット符号なし整数。The 8-bit unsigned integer to convert.

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.

戻り値

value の文字列形式。The string representation of value.

次の例では、en-us および fr-fr カルチャの書式指定規則を使用して、符号なしバイト配列の各要素を等価の文字列形式に変換します。The following example converts each element in an unsigned byte array to its equivalent string representation using the formatting conventions of the en-US and fr-FR cultures. 既定では、"G" 指定子はバイト値の文字列形式の10進数のみを出力providerするため、パラメーターは返される文字列の書式設定には影響しません。Because the "G" specifier by default outputs only decimal digits in a byte value's string representation, the provider parameter does not affect the formatting of the returned string.

byte[] numbers = { 12, 100, Byte.MaxValue };
// Define the culture names used to display them.
string[] cultureNames = { "en-US", "fr-FR" };

foreach (byte number in numbers)
{
   Console.WriteLine("{0}:", Convert.ToString(number,
                             System.Globalization.CultureInfo.InvariantCulture));
   foreach (string cultureName in cultureNames)
   {
      System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(cultureName);
      Console.WriteLine("   {0}: {1,20}",
                        culture.Name, Convert.ToString(number, culture));
   }
   Console.WriteLine();
}   
// The example displays the following output:
//       12:
//          en-US:                   12
//          fr-FR:                   12
//       
//       100:
//          en-US:                  100
//          fr-FR:                  100
//       
//       255:
//          en-US:                  255
//          fr-FR:                  255      
' Define an array of numbers to display.
Dim numbers() As Byte = { 12, 100, Byte.MaxValue }
' Define the culture names used to display them.
Dim cultureNames() As String = { "en-US", "fr-FR" }

For Each number As Byte In numbers
   Console.WriteLine("{0}:", Convert.ToString(number, _
                             System.Globalization.CultureInfo.InvariantCulture))
   For Each cultureName As String In cultureNames
      Dim culture As New System.Globalization.CultureInfo(cultureName)
      Console.WriteLine("   {0}: {1,20}", _
                        culture.Name, Convert.ToString(number, culture))
   Next
   Console.WriteLine()
Next   
' The example displays the following output:
'       12:
'          en-US:                   12
'          fr-FR:                   12
'       
'       100:
'          en-US:                  100
'          fr-FR:                  100
'       
'       255:
'          en-US:                  255
'          fr-FR:                  255      

注釈

この実装はとByte.ToString同じです。This implementation is identical to Byte.ToString.

ToString(Boolean)

指定したブール値を、それと等しい文字列形式に変換します。Converts the specified Boolean value to its equivalent string representation.

public:
 static System::String ^ ToString(bool value);
public static string ToString (bool value);
static member ToString : bool -> string
Public Shared Function ToString (value As Boolean) As String

パラメーター

value
Boolean

変換するブール値。The Boolean value to convert.

戻り値

value の文字列形式。The string representation of value.

次の例は、を使用しBooleanて、 StringをにToString変換する方法を示しています。The following example illustrates the conversion of a Boolean to a String, using ToString. また、変換によって返される文字列がまたはBoolean.TrueString Boolean.FalseStringのいずれかと等しいことも示されます。It also illustrates that the string returned by the conversion equals either Boolean.TrueString or Boolean.FalseString.

bool falseFlag = false;
bool trueFlag = true;

Console.WriteLine(Convert.ToString(falseFlag));
Console.WriteLine(Convert.ToString(falseFlag).Equals(Boolean.FalseString));
Console.WriteLine(Convert.ToString(trueFlag));
Console.WriteLine(Convert.ToString(trueFlag).Equals(Boolean.TrueString));
// The example displays the following output:
//       False
//       True
//       True
//       True
Dim falseFlag As Boolean = False
Dim trueFlag As Boolean = True

Console.WriteLine(Convert.ToString(falseFlag))
Console.WriteLine(Convert.ToString(falseFlag).Equals(Boolean.FalseString))
Console.WriteLine(Convert.ToString(trueFlag))
Console.WriteLine(Convert.ToString(trueFlag).Equals(Boolean.TrueString))
' The example displays the following output:
'       False
'       True
'       True
'       True      
let falseFlag = false
let trueFlag = true

Console.WriteLine (Convert.ToString falseFlag)
Console.WriteLine (Convert.ToString falseFlag=Boolean.FalseString)
Console.WriteLine (Convert.ToString trueFlag)
Console.WriteLine (Convert.ToString trueFlag=Boolean.TrueString)
// The example displays the following output:
//       False
//       True
//       True
//       True

注釈

この実装はとBoolean.ToString同じです。This implementation is identical to Boolean.ToString. 値とBoolean.TrueString true 値にfalse対してを返します。 Boolean.FalseStringIt returns Boolean.TrueString for true values and Boolean.FalseString for false values.

ToString(Byte)

指定した 8 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 8-bit unsigned integer to its equivalent string representation.

public:
 static System::String ^ ToString(System::Byte value);
public static string ToString (byte value);
static member ToString : byte -> string
Public Shared Function ToString (value As Byte) As String

パラメーター

value
Byte

変換する 8 ビット符号なし整数。The 8-bit unsigned integer to convert.

戻り値

value の文字列形式。The string representation of value.

次の例では、 Byte配列内の各値を文字列に変換します。The following example converts each value in a Byte array to a string.

using System;

public class Example
{
   public static void Main()
   {
      byte[] values = { Byte.MinValue, 12, 100, 179, Byte.MaxValue } ;

      foreach (var value in values)
         Console.WriteLine("{0,3} ({1}) --> {2}", value, 
                           value.GetType().Name, 
                           Convert.ToString(value));      
   }
}
// The example displays the following output:
//       0 (Byte) --> 0
//      12 (Byte) --> 12
//     100 (Byte) --> 100
//     179 (Byte) --> 179
//     255 (Byte) --> 255
Public Module Example
   Public Sub Main()
      Dim values() As Byte = { Byte.MinValue, 12, 100, 179, Byte.MaxValue }

      For Each value In values
         Console.WriteLine("{0,3} ({1}) --> {2}", value, 
                           value.GetType().Name, 
                           Convert.ToString(value))
      Next                           
   End Sub
End Module
' The example displays the following output:
'       0 (Byte) --> 0
'      12 (Byte) --> 12
'     100 (Byte) --> 100
'     179 (Byte) --> 179
'     255 (Byte) --> 255
let values = [ Byte.MinValue; 12uy; 100uy; 179uy; Byte.MaxValue ]
for value in values do
    printfn "% 4i (%s) --> %s" value (value.GetType().Name) (Convert.ToString value)
// The example displays the following output:
//       0 (Byte) --> 0
//      12 (Byte) --> 12
//     100 (Byte) --> 100
//     179 (Byte) --> 179
//     255 (Byte) --> 255

注釈

この実装はとByte.ToString()同じです。This implementation is identical to Byte.ToString().

ToString(Char)

指定した Unicode 文字の値を等価の文字列形式に変換します。Converts the value of the specified Unicode character to its equivalent string representation.

public:
 static System::String ^ ToString(char value);
public static string ToString (char value);
static member ToString : char -> string
Public Shared Function ToString (value As Char) As String

パラメーター

value
Char

変換する Unicode 文字。The Unicode character to convert.

戻り値

value の文字列形式。The string representation of value.

次の例ではChar 、をStringに変換します。The following example converts a Char to a String.

public:
   void ConvertStringChar( String^ stringVal )
   {
      Char charVal = 'a';
      
      // A String must be one character long to convert to char.
      try
      {
         charVal = System::Convert::ToChar( stringVal );
         System::Console::WriteLine( " {0} as a char is {1}",
            stringVal, charVal );
      }
      catch ( System::FormatException^ ) 
      {
         System::Console::WriteLine(
            "The String is longer than one character." );
      }
      catch ( System::ArgumentNullException^ ) 
      {
         System::Console::WriteLine( "The String is 0." );
      }
      
      // A char to String conversion will always succeed.
      stringVal = System::Convert::ToString( charVal );
      System::Console::WriteLine( "The character as a String is {0}",
         stringVal );
   }
public void ConvertStringChar(string stringVal) {
    char charVal = 'a';

    // A string must be one character long to convert to char.
    try {
        charVal = System.Convert.ToChar(stringVal);
        System.Console.WriteLine("{0} as a char is {1}",
            stringVal, charVal);
    }
    catch (System.FormatException) {
        System.Console.WriteLine(
            "The string is longer than one character.");
    }
    catch (System.ArgumentNullException) {
        System.Console.WriteLine("The string is null.");
    }

    // A char to string conversion will always succeed.
    stringVal = System.Convert.ToString(charVal);
    System.Console.WriteLine("The character as a string is {0}",
            stringVal);
}
Public Sub ConvertStringChar(ByVal stringVal As String)
    Dim charVal As Char = "a"c

    ' A string must be one character long to convert to char.
    Try
        charVal = System.Convert.ToChar(stringVal)
        System.Console.WriteLine("{0} as a char is {1}", _
                                  stringVal, charVal)
    Catch exception As System.FormatException
        System.Console.WriteLine( _
         "The string is longer than one character.")
    Catch exception As System.ArgumentNullException
        System.Console.WriteLine("The string is null.")
    End Try

    ' A char to string conversion will always succeed.
    stringVal = System.Convert.ToString(charVal)
    System.Console.WriteLine("The character as a string is {0}", _
                              stringVal)
End Sub

注釈

この実装はとChar.ToString同じです。This implementation is identical to Char.ToString.

ToString(Decimal)

指定した 10 進数値を、それと等しい文字列形式に変換します。Converts the value of the specified decimal number to its equivalent string representation.

public:
 static System::String ^ ToString(System::Decimal value);
public static string ToString (decimal value);
static member ToString : decimal -> string
Public Shared Function ToString (value As Decimal) As String

パラメーター

value
Decimal

変換する 10 進数。The decimal number to convert.

戻り値

value の文字列形式。The string representation of value.

次の例ではDecimal 、をStringに変換します。The following example converts a Decimal to a String.

public:
   void ConvertStringDecimal( String^ stringVal )
   {
      Decimal decimalVal = 0;

      try
      {
         decimalVal = System::Convert::ToDecimal( stringVal );
         System::Console::WriteLine( "The String as a decimal is {0}.",
         decimalVal );
      }
      catch ( System::OverflowException^ ) 
      {
         System::Console::WriteLine(
            "The conversion from String to decimal overflowed." );
      }
      catch ( System::FormatException^ ) 
      {
         System::Console::WriteLine(
            "The String is not formatted as a decimal." );
      }
      catch ( System::ArgumentNullException^ ) 
      {
         System::Console::WriteLine( "The String is 0." );
      }
      
      // Decimal to String conversion will not overflow.
      stringVal = System::Convert::ToString( decimalVal );
      System::Console::WriteLine(
         "The decimal as a String is {0}.", stringVal );
   }
public void ConvertStringDecimal(string stringVal) {
    decimal decimalVal = 0;
    
    try {
        decimalVal = System.Convert.ToDecimal(stringVal);
        System.Console.WriteLine(
            "The string as a decimal is {0}.", decimalVal);
    } 
    catch (System.OverflowException){
        System.Console.WriteLine(
            "The conversion from string to decimal overflowed.");
    }
    catch (System.FormatException) {
        System.Console.WriteLine(
            "The string is not formatted as a decimal.");
    }
    catch (System.ArgumentNullException) {
        System.Console.WriteLine(
            "The string is null.");
    }

    // Decimal to string conversion will not overflow.
    stringVal = System.Convert.ToString(decimalVal);
    System.Console.WriteLine(
        "The decimal as a string is {0}.", stringVal);
}	
Public Sub ConvertStringDecimal(ByVal stringVal As String)
    Dim decimalVal As Decimal = 0

    Try
        decimalVal = System.Convert.ToDecimal(stringVal)
        System.Console.WriteLine("The string as a decimal is {0}.", _
                                  decimalVal)
    Catch exception As System.OverflowException
        System.Console.WriteLine( _
            "Overflow in string-to-decimal conversion.")
    Catch exception As System.FormatException
        System.Console.WriteLine( _
            "The string is not formatted as a decimal.")
    Catch exception As System.ArgumentException
        System.Console.WriteLine("The string is null.")
    End Try

    ' Decimal to string conversion will not overflow.
    stringVal = System.Convert.ToString(decimalVal)
    System.Console.WriteLine("The decimal as a string is {0}.", _
                              stringVal)
End Sub

注釈

この実装はとDecimal.ToString()同じです。This implementation is identical to Decimal.ToString().

ToString(Double)

指定した倍精度浮動小数点数値を等価の文字列形表記に変換します。Converts the value of the specified double-precision floating-point number to its equivalent string representation.

public:
 static System::String ^ ToString(double value);
public static string ToString (double value);
static member ToString : double -> string
Public Shared Function ToString (value As Double) As String

パラメーター

value
Double

変換する倍精度浮動小数点数。The double-precision floating-point number to convert.

戻り値

value の文字列形式。The string representation of value.

次の例ではDouble 、をStringに変換します。The following example converts a Double to a String.

public:
   void ConvertDoubleString( double doubleVal )
   {
      String^ stringVal;
      
      // A conversion from Double to String cannot overflow.
      stringVal = System::Convert::ToString( doubleVal );
      System::Console::WriteLine( " {0} as a String is: {1}",
         doubleVal, stringVal );
      try
      {
         doubleVal = System::Convert::ToDouble( stringVal );
         System::Console::WriteLine( " {0} as a double is: {1}",
         stringVal, doubleVal );
      }
      catch ( System::OverflowException^ ) 
      {
         System::Console::WriteLine( "Conversion from String-to-double overflowed." );
      }
      catch ( System::FormatException^ ) 
      {
         System::Console::WriteLine( "The String was not formatted as a double." );
      }
      catch ( System::ArgumentException^ ) 
      {
         System::Console::WriteLine( "The String pointed to null." );
      }
   }
public void ConvertDoubleString(double doubleVal) {
    
    string	stringVal;     

    // A conversion from Double to string cannot overflow.       
    stringVal = System.Convert.ToString(doubleVal);
    System.Console.WriteLine("{0} as a string is: {1}",
        doubleVal, stringVal);

    try {
        doubleVal = System.Convert.ToDouble(stringVal);
        System.Console.WriteLine("{0} as a double is: {1}",
            stringVal, doubleVal);
    } 
    catch (System.OverflowException) {
        System.Console.WriteLine(
            "Conversion from string-to-double overflowed.");
    }
    catch (System.FormatException) {
        System.Console.WriteLine(
            "The string was not formatted as a double.");
    }
    catch (System.ArgumentException) {
        System.Console.WriteLine(
            "The string pointed to null.");
    }
}
Public Sub ConvertDoubleString(ByVal doubleVal As Double)

    Dim stringVal As String

    ' A conversion from Double to String cannot overflow.       
    stringVal = System.Convert.ToString(doubleVal)
    System.Console.WriteLine("{0} as a String is: {1}", _
                              doubleVal, stringVal)

    Try
        doubleVal = System.Convert.ToDouble(stringVal)
        System.Console.WriteLine("{0} as a Double is: {1}", _
                                  stringVal, doubleVal)
    Catch exception As System.OverflowException
        System.Console.WriteLine( _
            "Overflow in String-to-Double conversion.")
    Catch exception As System.FormatException
        System.Console.WriteLine( _
            "The string is not formatted as a Double.")
    Catch exception As System.ArgumentException
        System.Console.WriteLine("The string is null.")
    End Try

End Sub

注釈

この実装はとDouble.ToString()同じです。This implementation is identical to Double.ToString().

ToString(Int16)

指定した 16 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 16-bit signed integer to its equivalent string representation.

public:
 static System::String ^ ToString(short value);
public static string ToString (short value);
static member ToString : int16 -> string
Public Shared Function ToString (value As Short) As String

パラメーター

value
Int16

変換する 16 ビット符号付き整数。The 16-bit signed integer to convert.

戻り値

value の文字列形式。The string representation of value.

次の例では、16ビット整数の配列内の各要素を、それと等価な文字列形式に変換します。The following example converts each element in an array of 16-bit integers to its equivalent string representation.

short[] numbers = { Int16.MinValue, -138, 0, 19, Int16.MaxValue };
string result;

foreach (short number in numbers)
{
   result = Convert.ToString(number);
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                        number.GetType().Name, number,
                        result.GetType().Name, result);
}     
// The example displays the following output:
//    Converted the Int16 value -32768 to the String value -32768.
//    Converted the Int16 value -138 to the String value -138.
//    Converted the Int16 value 0 to the String value 0.
//    Converted the Int16 value 19 to the String value 19.
//    Converted the Int16 value 32767 to the String value 32767.
Dim numbers() As Short = { Int16.MinValue, -138, 0, 19, Int16.MaxValue }
Dim result As String

For Each number As Short In numbers
   result = Convert.ToString(number)
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.", _
                        number.GetType().Name, number, _
                        result.GetType().Name, result)
Next     
' The example displays the following output:
'    Converted the Int16 value -32768 to the String value -32768.
'    Converted the Int16 value -138 to the String value -138.
'    Converted the Int16 value 0 to the String value 0.
'    Converted the Int16 value 19 to the String value 19.
'    Converted the Int16 value 32767 to the String value 32767.

注釈

この実装はとInt16.ToString()同じです。This implementation is identical to Int16.ToString().

ToString(DateTime)

指定した DateTime の値を等価の文字列形式に変換します。Converts the value of the specified DateTime to its equivalent string representation.

public:
 static System::String ^ ToString(DateTime value);
public static string ToString (DateTime value);
static member ToString : DateTime -> string
Public Shared Function ToString (value As DateTime) As String

パラメーター

value
DateTime

変換する日時の値。The date and time value to convert.

戻り値

value の文字列形式。The string representation of value.

次の例では、 DateTime値の配列内の各要素Stringを値に変換します。The following example converts each element in an array of a DateTime value to a String value.

DateTime[] dates = { new DateTime(2009, 7, 14), 
                     new DateTime(1, 1, 1, 18, 32, 0), 
                     new DateTime(2009, 2, 12, 7, 16, 0) };
string result;

foreach (DateTime dateValue in dates)
{
   result = Convert.ToString(dateValue);
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                        dateValue.GetType().Name, dateValue,
                        result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the DateTime value 7/14/2009 12:00:00 AM to a String value 7/14/2009 12:00:00 AM.
//    Converted the DateTime value 1/1/0001 06:32:00 PM to a String value 1/1/0001 06:32:00 PM.
//    Converted the DateTime value 2/12/2009 07:16:00 AM to a String value 2/12/2009 07:16:00 AM.
Dim dates() As Date = { #07/14/2009#, #6:32PM#, #02/12/2009 7:16AM#}
Dim result As String

For Each dateValue As Date In dates
   result = Convert.ToString(dateValue)
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.", _
                        dateValue.GetType().Name, dateValue, _
                        result.GetType().Name, result)
Next
' The example displays the following output:
'    Converted the DateTime value 7/14/2009 12:00:00 AM to a String value 7/14/2009 12:00:00 AM.
'    Converted the DateTime value 1/1/0001 06:32:00 PM to a String value 1/1/0001 06:32:00 PM.
'    Converted the DateTime value 2/12/2009 07:16:00 AM to a String value 2/12/2009 07:16:00 AM.

注釈

この実装はとDateTime.ToString()同じです。This implementation is identical to DateTime.ToString(). 現在のカルチャの書式指定規則と "G" 書式指定子を使用して、 DateTime値を文字列形式に変換します。It uses the formatting conventions of the current culture and the "G" format specifier to convert a DateTime value to its string representation.

ToString(Int64)

指定した 64 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 64-bit signed integer to its equivalent string representation.

public:
 static System::String ^ ToString(long value);
public static string ToString (long value);
static member ToString : int64 -> string
Public Shared Function ToString (value As Long) As String

パラメーター

value
Int64

変換する 64 ビット符号付き整数。The 64-bit signed integer to convert.

戻り値

value の文字列形式。The string representation of value.

次の例では、長整数配列内の各要素を、それと等価な文字列形式に変換します。The following example converts each element in a long integer array to its equivalent string representation.

// Create a NumberFormatInfo object and set several of its
// properties that control default integer formatting.
System.Globalization.NumberFormatInfo provider = new System.Globalization.NumberFormatInfo();
provider.NegativeSign = "minus ";

long[] values = { -200, 0, 1000 };

foreach (long value in values)
   Console.WriteLine("{0,-6}  -->  {1,10}", 
                     value, Convert.ToString(value, provider));
// The example displays the following output:
//       -200    -->   minus 200
//       0       -->           0
//       1000    -->        1000
' Create a NumberFormatInfo object and set several of its
' properties that control default integer formatting.
Dim provider As New System.Globalization.NumberFormatInfo()
provider.NegativeSign = "minus "

Dim values() As Long = { -200, 0, 1000 }

For Each value As Long In values
   Console.WriteLine("{0,-6}  -->  {1,10}", _
                     value, Convert.ToString(value, provider))
Next
' The example displays the following output:
'       -200    -->   minus 200
'       0       -->           0
'       1000    -->        1000

注釈

この実装はとInt64.ToString()同じです。This implementation is identical to Int64.ToString().

ToString(Object)

指定したオブジェクトの値を等価の文字列表記に変換します。Converts the value of the specified object to its equivalent string representation.

public:
 static System::String ^ ToString(System::Object ^ value);
public static string ToString (object value);
static member ToString : obj -> string
Public Shared Function ToString (value As Object) As String

パラメーター

value
Object

変換する値を提供するオブジェクト、または nullAn object that supplies the value to convert, or null.

戻り値

value の文字列形式。valuenull の場合は EmptyThe string representation of value, or Empty if value is null.

次の例では、オブジェクト配列内の各要素を、それと等価な文字列形式に変換します。The following example converts each element in an object array to its equivalent string representation.

object[] values = { false, 12.63m, new DateTime(2009, 6, 1, 6, 32, 15), 16.09e-12,
                    'Z', 15.15322, SByte.MinValue, Int32.MaxValue };
string result;

foreach (object value in values)
{
   result = Convert.ToString(value);
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                        value.GetType().Name, value,
                        result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the Boolean value False to the String value False.
//    Converted the Decimal value 12.63 to the String value 12.63.
//    Converted the DateTime value 6/1/2009 06:32:15 AM to the String value 6/1/2009 06:32:15 AM.
//    Converted the Double value 1.609E-11 to the String value 1.609E-11.
//    Converted the Char value Z to the String value Z.
//    Converted the Double value 15.15322 to the String value 15.15322.
//    Converted the SByte value -128 to the String value -128.
//    Converted the Int32 value 2147483647 to the String value 2147483647.      
Dim values() As Object = { False, 12.63d, #06/01/2009 6:32:15#, 16.09e-12, _
                           "Z"c, 15.15322, SByte.MinValue, Int32.MaxValue}
Dim result As String

For Each value As Object In values
   result = Convert.ToString(value)
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.", _
                        value.GetType().Name, value, _
                        result.GetType().Name, result)
Next
' The example displays the following output:
'    Converted the Boolean value False to the String value False.
'    Converted the Decimal value 12.63 to the String value 12.63.
'    Converted the DateTime value 6/1/2009 06:32:15 AM to the String value 6/1/2009 06:32:15 AM.
'    Converted the Double value 1.609E-11 to the String value 1.609E-11.
'    Converted the Char value Z to the String value Z.
'    Converted the Double value 15.15322 to the String value 15.15322.
'    Converted the SByte value -128 to the String value -128.
'    Converted the Int32 value 2147483647 to the String value 2147483647.      

注釈

文字列形式valueに変換するために、メソッドはのvalue実装のIConvertible.ToString呼び出しを試みます。To convert value to its string representation, the method tries to call the IConvertible.ToString implementation of value. valueインターフェイスをIConvertible実装していない場合、メソッドはのIFormattable.ToString value実装の呼び出しを試みます。If value does not implement the IConvertible interface, the method tries to call the IFormattable.ToString implementation of value. Value がインターフェイスをIFormattable実装していない場合、メソッドは、基になるのvalue型のToStringメソッドを呼び出します。If value does not implement the IFormattable interface, the method calls the ToString method of the underlying type of value.

ToString(SByte)

重要

この API は CLS 準拠ではありません。

指定した 8 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 8-bit signed integer to its equivalent string representation.

public:
 static System::String ^ ToString(System::SByte value);
[System.CLSCompliant(false)]
public static string ToString (sbyte value);
static member ToString : sbyte -> string
Public Shared Function ToString (value As SByte) As String

パラメーター

value
SByte

変換する 8 ビット符号付き整数。The 8-bit signed integer to convert.

戻り値

value の文字列形式。The string representation of value.

属性

次の例では、符号付きバイト配列の各要素を、それと等価な文字列形式に変換します。The following example converts each element in a signed byte array to its equivalent string representation.

sbyte[] numbers = { SByte.MinValue, -12, 0, 16, SByte.MaxValue };
string result;

foreach (sbyte number in numbers)
{
   result = Convert.ToString(number);
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                        number.GetType().Name, number,
                        result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the SByte value -128 to the String value -128.
//    Converted the SByte value -12 to the String value -12.
//    Converted the SByte value 0 to the String value 0.
//    Converted the SByte value 16 to the String value 16.
//    Converted the SByte value 127 to the String value 127.
Dim numbers() As SByte = { SByte.MinValue, -12, 0, 16, SByte.MaxValue }
Dim result As String

For Each number As SByte In numbers
   result = Convert.ToString(number)
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.", _
                        number.GetType().Name, number, _
                        result.GetType().Name, result)
Next
' The example displays the following output:
'    Converted the SByte value -128 to the String value -128.
'    Converted the SByte value -12 to the String value -12.
'    Converted the SByte value 0 to the String value 0.
'    Converted the SByte value 16 to the String value 16.
'    Converted the SByte value 127 to the String value 127.

注釈

この実装はとSByte.ToString()同じです。This implementation is identical to SByte.ToString().

ToString(Single)

指定した単精度浮動小数点数値を等価の文字列形式に変換します。Converts the value of the specified single-precision floating-point number to its equivalent string representation.

public:
 static System::String ^ ToString(float value);
public static string ToString (float value);
static member ToString : single -> string
Public Shared Function ToString (value As Single) As String

パラメーター

value
Single

変換する単精度浮動小数点数。The single-precision floating-point number to convert.

戻り値

value の文字列形式。The string representation of value.

次の例では、値のSingle配列内の各要素を、それと等価な文字列形式に変換します。The following example converts each element in an array of Single values to its equivalent string representation.

float[] numbers = { Single.MinValue, -1011.351f, -17.45f, -3e-16f,
                    0f, 4.56e-12f, 16.0001f, 10345.1221f, Single.MaxValue };
string result;

foreach (float number in numbers)
{
   result = Convert.ToString(number);
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                        number.GetType().Name, number,
                        result.GetType().Name, result);
}                            
// The example displays the following output:
//    Converted the Single value -3.402823E+38 to the String value -3.402823E+38.
//    Converted the Single value -1011.351 to the String value -1011.351.
//    Converted the Single value -17.45 to the String value -17.45.
//    Converted the Single value -3E-16 to the String value -3E-16.
//    Converted the Single value 0 to the String value 0.
//    Converted the Single value 4.56E-12 to the String value 4.56E-12.
//    Converted the Single value 16.0001 to the String value 16.0001.
//    Converted the Single value 10345.12 to the String value 10345.12.
//    Converted the Single value 3.402823E+38 to the String value 3.402823E+38.
Dim numbers() As Single = { Single.MinValue, -1011.351, -17.45, -3e-16, _
                            0, 4.56e-12, 16.0001, 10345.1221, Single.MaxValue }
Dim result As String

For Each number As Single In numbers
   result = Convert.ToString(number)
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.", _
                        number.GetType().Name, number, _
                        result.GetType().Name, result)
Next                            
' The example displays the following output:
'    Converted the Single value -3.402823E+38 to the String value -3.402823E+38.
'    Converted the Single value -1011.351 to the String value -1011.351.
'    Converted the Single value -17.45 to the String value -17.45.
'    Converted the Single value -3E-16 to the String value -3E-16.
'    Converted the Single value 0 to the String value 0.
'    Converted the Single value 4.56E-12 to the String value 4.56E-12.
'    Converted the Single value 16.0001 to the String value 16.0001.
'    Converted the Single value 10345.12 to the String value 10345.12.
'    Converted the Single value 3.402823E+38 to the String value 3.402823E+38.

注釈

この実装はとSingle.ToString()同じです。This implementation is identical to Single.ToString().

ToString(String)

指定した文字列インスタンスを返します。実際の変換は実行されません。Returns the specified string instance; no actual conversion is performed.

public:
 static System::String ^ ToString(System::String ^ value);
public static string ToString (string value);
static member ToString : string -> string
Public Shared Function ToString (value As String) As String

パラメーター

value
String

返される文字列。The string to return.

戻り値

value は変更されずに返されます。value is returned unchanged.

次の例では、文字列をToString(String)メソッドに渡し、 Object.ReferenceEqualsメソッドを呼び出して、メソッドが元の文字列を返すことを確認します。The following example passes a string to the ToString(String) method and calls the Object.ReferenceEquals method to confirm that the method returns the original string. また、この例でString.IsInternedは、元の文字列がインターンプールされているため、2つの文字列が同一でないことを確認するためにメソッドを呼び出します。The example also calls the String.IsInterned method to ensure that the two strings are not identical because the original string is interned.

using System;

public class Example
{
   public static void Main()
   {
      String article = "An";
      String noun = "apple";
      String str1 = String.Format("{0} {1}", article, noun);
      String str2 = Convert.ToString(str1);

      Console.WriteLine("str1 is interned: {0}",
                        ! (String.IsInterned(str1) == null));
      Console.WriteLine("str1 and str2 are the same reference: {0}",
                        Object.ReferenceEquals(str1, str2));
   }
}
// The example displays the following output:
//       str1 is interned: False
//       str1 and str2 are the same reference: True
Module Example
   Public Sub Main()
      Dim article As String = "An"
      Dim noun As String = "apple"
      Dim str1 As String = String.Format("{0} {1}", article, noun)
      Dim str2 As String = Convert.ToString(str1)

      Console.WriteLine("str1 is interned: {0}",
                        Not String.IsInterned(str1) Is Nothing)
      Console.WriteLine("str1 and str2 are the same reference: {0}",
                        Object.ReferenceEquals(str1, str2))
   End Sub
End Module
' The example displays the following output:
'       str1 is interned: False
'       str1 and str2 are the same reference: True

ToString(UInt16)

重要

この API は CLS 準拠ではありません。

指定した 16 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 16-bit unsigned integer to its equivalent string representation.

public:
 static System::String ^ ToString(System::UInt16 value);
[System.CLSCompliant(false)]
public static string ToString (ushort value);
static member ToString : uint16 -> string
Public Shared Function ToString (value As UShort) As String

パラメーター

value
UInt16

変換する 16 ビット符号なし整数。The 16-bit unsigned integer to convert.

戻り値

value の文字列形式。The string representation of value.

属性

次の例では、符号なし16ビット整数値の配列内の各要素を、それと等価な文字列形式に変換します。The following example converts each element in an array of unsigned 16-bit integer values to its equivalent string representation.

ushort[] numbers = { UInt16.MinValue, 103, 1045, UInt16.MaxValue };
string result;

foreach (ushort number in numbers)
{
   result = Convert.ToString(number);
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                        number.GetType().Name, number,
                        result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the UInt16 value 0 to the String value 0.
//    Converted the UInt16 value 103 to the String value 103.
//    Converted the UInt16 value 1045 to the String value 1045.
//    Converted the UInt16 value 65535 to the String value 65535.
Dim numbers() As UShort = { UInt16.MinValue, 103, 1045, UInt16.MaxValue }
Dim result As String

For Each number As UShort In numbers
   result = Convert.ToString(number)
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.", _
                        number.GetType().Name, number, _
                        result.GetType().Name, result)
Next
' The example displays the following output:
'    Converted the UInt16 value 0 to the String value 0.
'    Converted the UInt16 value 103 to the String value 103.
'    Converted the UInt16 value 1045 to the String value 1045.
'    Converted the UInt16 value 65535 to the String value 65535.

注釈

この実装はとUInt16.ToString()同じです。This implementation is identical to UInt16.ToString().

ToString(UInt32)

重要

この API は CLS 準拠ではありません。

指定した 32 ビット符号なし整数の値を等価の文字列形式に変換します。Converts the value of the specified 32-bit unsigned integer to its equivalent string representation.

public:
 static System::String ^ ToString(System::UInt32 value);
[System.CLSCompliant(false)]
public static string ToString (uint value);
static member ToString : uint32 -> string
Public Shared Function ToString (value As UInteger) As String

パラメーター

value
UInt32

変換する 32 ビット符号なし整数。The 32-bit unsigned integer to convert.

戻り値

value の文字列形式。The string representation of value.

属性

次の例では、符号なし整数配列内の各要素を、それと等価な文字列形式に変換します。The following example converts each element in an unsigned integer array to its equivalent string representation.

uint[] numbers = { UInt32.MinValue, 103, 1045, 119543, UInt32.MaxValue };
string result;

foreach (uint number in numbers)
{
   result = Convert.ToString(number);
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                        number.GetType().Name, number,
                        result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the UInt32 value 0 to the String value 0.
//    Converted the UInt32 value 103 to the String value 103.
//    Converted the UInt32 value 1045 to the String value 1045.
//    Converted the UInt32 value 119543 to the String value 119543.
//    Converted the UInt32 value 4294967295 to the String value 4294967295.
Dim numbers() As UInteger = { UInt32.MinValue, 103, 1045, 119543, UInt32.MaxValue }
Dim result As String

For Each number As UInteger In numbers
   result = Convert.ToString(number)
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.", _
                        number.GetType().Name, number, _
                        result.GetType().Name, result)
Next
' The example displays the following output:
'    Converted the UInt32 value 0 to the String value 0.
'    Converted the UInt32 value 103 to the String value 103.
'    Converted the UInt32 value 1045 to the String value 1045.
'    Converted the UInt32 value 119543 to the String value 119543.
'    Converted the UInt32 value 4294967295 to the String value 4294967295.

注釈

この実装はとUInt32.ToString()同じです。This implementation is identical to UInt32.ToString().

ToString(Int32)

指定した 32 ビット符号付き整数の値を等価の文字列形式に変換します。Converts the value of the specified 32-bit signed integer to its equivalent string representation.

public:
 static System::String ^ ToString(int value);
public static string ToString (int value);
static member ToString : int -> string
Public Shared Function ToString (value As Integer) As String

パラメーター

value
Int32

変換する 32 ビット符号付き整数。The 32-bit signed integer to convert.

戻り値

value の文字列形式。The string representation of value.

次の例ではToString(Int32) 、メソッドToString(UInt16, IFormatProvider)とメソッドを比較しています。The following example compares the ToString(Int32) method with the ToString(UInt16, IFormatProvider) method. 負の符号をNumberFormatInfo表すために "マイナス" を使用するカスタムオブジェクトを定義します。It defines a custom NumberFormatInfo object that uses the sting "minus" to represent the negative sign. これは、整数の配列内の各要素を、既定の書式 (現在のカルチャの書式指定規則) およびカスタム書式プロバイダーを使用して、それと等価な文字列形式に変換します。It converts each element in an integer array to its equivalent string representation using default formatting (the formatting conventions of the current culture) and the custom format provider.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      // Create a NumberFormatInfo object and set its NegativeSigns
      // property to use for integer formatting.
      NumberFormatInfo provider = new NumberFormatInfo();
      provider.NegativeSign = "minus ";

      int[] values = { -20, 0, 100 };
      
      Console.WriteLine("{0,-8} --> {1,10} {2,10}\n", "Value",
                         CultureInfo.CurrentCulture.Name,
                         "Custom");
      foreach (int value in values)
         Console.WriteLine("{0,-8} --> {1,10} {2,10}",
                           value, Convert.ToString(value),
                           Convert.ToString(value, provider));
      // The example displays output like the following:
      //       Value    -->      en-US     Custom
      //
      //       -20      -->        -20   minus 20
      //       0        -->          0          0
      //       100      -->        100        100
Imports System.Globalization

Module Example
   Public Sub Main()
      ' Create a NumberFormatInfo object and set its NegativeSigns
      ' property to use for integer formatting.
      Dim provider As New NumberFormatInfo()
      provider.NegativeSign = "minus "

      Dim values() As Integer = { -20, 0, 100 }

      Console.WriteLine("{0,-8} --> {1,10} {2,10}", "Value",
                         CultureInfo.CurrentCulture.Name,
                         "Custom")
      Console.WriteLine()
      For Each value As Integer In values
         Console.WriteLine("{0,-8} --> {1,10} {2,10}",
                           value, Convert.ToString(value),
                           Convert.ToString(value, provider))
      Next
   End Sub
End Module
' The example displays output like the following:
'       Value    -->      en-US     Custom
'
'       -20      -->        -20   minus 20
'       0        -->          0          0
'       100      -->        100        100

注釈

この実装はとInt32.ToString()同じです。This implementation is identical to Int32.ToString(). 現在のvalueスレッドカルチャの書式指定規則を使用して書式設定します。It formats value by using the formatting conventions of the current thread culture.

適用対象