Convert.ToString メソッドとは? わかりやすく解説

Convert.ToString メソッド (UInt32)

指定した 32 ビット符号なし整数の値を等価String 形式変換します

このメソッドは、CLS準拠していません。  

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
Public Shared Function ToString
 ( _
    value As UInteger _
) As String
Dim value As UInteger
Dim returnValue As String

returnValue = Convert.ToString(value)
[CLSCompliantAttribute(false)] 
public static string ToString
 (
    uint value
)
[CLSCompliantAttribute(false)] 
public:
static String^ ToString (
    unsigned int value
)
/** @attribute CLSCompliantAttribute(false) */ 
public static String ToString (
    UInt32 value
)
CLSCompliantAttribute(false) 
public static function ToString
 (
    value : uint
) : String

パラメータ

value

32 ビット符号なし整数

戻り値
value の値と等価String

解説解説

この実装は、UInt32.ToString と同じです。

使用例使用例

既定書式設定使用してToString メソッド32 ビット符号なし整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Byte)

指定した 8 ビット符号なし整数の値を等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

この実装は、Byte.ToString と同じです。

使用例使用例

ToString使用してByteString変換する方法については、次のコード例参照してください

Public Sub ConvertStringByte(ByVal
 stringVal As String)
    Dim byteVal As Byte
 = 0

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

    'The conversion from byte to string is always valid.
    stringVal = System.Convert.ToString(byteVal)
    System.Console.WriteLine("{0} as a string is {1}",
 _
                              byteVal, stringVal)
End Sub
public void ConvertStringByte(string
 stringVal) {
    byte byteVal = 0;
    
    try {
        byteVal = System.Convert.ToByte(stringVal);
        System.Console.WriteLine("{0} as a byte is: {1}",
            stringVal, byteVal);
    } 
    catch (System.OverflowException) {
        System.Console.WriteLine(
            "Conversion from string to byte overflowed.");
    }
    catch (System.FormatException) {
        System.Console.WriteLine(
            "The string is not formatted as a byte.");
    }
    catch (System.ArgumentNullException) {
        System.Console.WriteLine(
            "The string is null.");
    }
    
    //The conversion from byte to string is always valid.
    stringVal = System.Convert.ToString(byteVal);
    System.Console.WriteLine("{0} as a string is {1}"
,
        byteVal, stringVal);
}
public:
   void ConvertStringByte( String^ stringVal )
   {
      Byte byteVal = 0;

      try
      {
         byteVal = System::Convert::ToByte( stringVal );
         System::Console::WriteLine( " {0} as a Byte is: {1}",
            stringVal, byteVal );
      }
      catch ( System::OverflowException^ ) 
      {
         System::Console::WriteLine(
            "Conversion from String to Byte overflowed." );
      }
      catch ( System::FormatException^ ) 
      {
         System::Console::WriteLine(
            "The String is not formatted as a Byte." );
      }
      catch ( System::ArgumentNullException^ ) 
      {
         System::Console::WriteLine( "The String is 0." );
      }
      
      //The conversion from Byte to String is always valid.
      stringVal = System::Convert::ToString( byteVal );
      System::Console::WriteLine( " {0} as a String is {1}",
         byteVal, stringVal );
   }
public void ConvertStringByte(String stringVal)
 
{
    ubyte byteVal = 0;

    try {        
        byteVal = System.Convert.ToByte(stringVal);
        System.Console.WriteLine("{0} as a byte is: {1}", stringVal, 
            System.Convert.ToString(byteVal));
    }
    catch (System.OverflowException exp) {        
        System.Console.WriteLine(
            "Conversion from string to byte overflowed.");
    }
    catch (System.FormatException exp) {        
        System.Console.WriteLine("The string is not formatted
 as a byte.");
    }
    catch (System.ArgumentNullException exp) {        
        System.Console.WriteLine("The string is null.");
    }

    //The conversion from byte to string is always valid.
    stringVal = System.Convert.ToString(byteVal);
    System.Console.WriteLine("{0} as a string is {1}"
, 
        System.Convert.ToString(byteVal), stringVal);
} //ConvertStringByte
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Object)

指定した Object の値を、その String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Object _
) As String

パラメータ

value

Object または null 参照 (Visual Basic では Nothing)。

戻り値
String 形式での value の値。値が null 参照 (Visual Basic では Nothing) の場合は String.Empty。

解説解説

戻り値は、value の基になる型の ToString メソッド呼び出した結果得られる値です。

使用例使用例

既定書式設定使用しToString メソッド数値以外の Objectボックス内の数値String変換するコード例次に示します

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

' 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
// 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
 ).
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 ).
import System.* ;
import 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 Object GetFormat(Type argType) 
    {
        // Here, the type of argType is displayed, and GetFormat
        // always returns Nothing.
        Console.Write("{0,-40}", argType.ToString());
        return null ;
    } //GetFormat
} //DummyProvider

class ConvertNonNumericProviderDemo
{   
    public static void main(String[]
 args)
    {  
        // 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 = (System.Double)(-98765.4321);
        DateTime dayTimeA =  new DateTime(2001, 9, 11, 13, 45,
 0);
      
        boolean 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);
    } //main
} //ConvertNonNumericProviderDemo

/*
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@33c0d9d

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Int16, Int32)

16 ビット符号付き整数の値を、指定した基数等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Short, _
    toBase As Integer _
) As String
Dim value As Short
Dim toBase As Integer
Dim returnValue As String

returnValue = Convert.ToString(value, toBase)
public static string ToString
 (
    short value,
    int toBase
)
public:
static String^ ToString (
    short value, 
    int toBase
)
public static String ToString (
    short value, 
    int toBase
)
public static function ToString
 (
    value : short, 
    toBase : int
) : String

パラメータ

value

16 ビット符号付き整数

toBase

戻り値基数。これは 2、8、10、または 16 である必要があります

戻り値
基数 toBase での valueString 形式

例外例外
例外種類条件

ArgumentException

toBase が 2、8、10、または 16 ではありません。

使用例使用例

ToString メソッド使用して、このメソッドサポートする基数に従って複数16 ビット整数String変換するコード例次に示します

' Example of the Convert.ToString( Short, Integer ) method.
Imports System
Imports Microsoft.VisualBasic

Module ConvertRadixShortDemo
    
    Sub RunToStringDemo( )

        Dim values as Short(
 ) = { _
            Short.MinValue, _
            -100, _
            999, _
            Short.MaxValue }
        Dim radices as Integer(
 ) = { 2, 8, 10, 16 }

        ' Iterate through the values array.
        Dim value as Short
        For Each value in
 values

            ' Iterate through the radices.
            Dim radix as Integer
            For Each radix in
 radices

                ' Convert a value with a radix.
                Dim valueString As String
 = _
                    Convert.ToString( value, radix )

                Console.WriteLine( "{0,8}  {1,3}    {2}",
 _
                    value, radix, valueString )
            Next radix
        Next value
    End Sub 

    Sub Main( )

        Console.WriteLine( _
            "This example of Convert.ToString( Short, Integer
 ) " & _ 
            "generates " & vbCrLf & "the
 following output. It " & _
            "converts several Short values to " &
 vbCrLf & "strings " & _
            "using the radixes supported by the method."
 )
        Console.WriteLine( vbCrLf & _
            "   Value  Radix  String" & vbCrLf
 & _
            "   -----  -----  ------" )

        RunToStringDemo( )

    End Sub 
End Module 

' This example of Convert.ToString( Short, Integer ) generates
' the following output. It converts several Short values to
' strings using the radixes supported by the method.
' 
'    Value  Radix  String
'    -----  -----  ------
'   -32768    2    1000000000000000
'   -32768    8    100000
'   -32768   10    -32768
'   -32768   16    8000
'     -100    2    1111111110011100
'     -100    8    177634
'     -100   10    -100
'     -100   16    ff9c
'      999    2    1111100111
'      999    8    1747
'      999   10    999
'      999   16    3e7
'    32767    2    111111111111111
'    32767    8    77777
'    32767   10    32767
'    32767   16    7fff
// Example of the Convert.ToString( short, int ) method.
using System;

class ConvertRadixShortDemo
{
    static void RunToStringDemo( )
    {
        short[ ] values = {
            short.MinValue, 
            -100, 
            999, 
            short.MaxValue };
        int[ ]  radices = { 2, 8, 10, 16 };

        // Iterate through the values array.
        foreach( short value in values )
        {
            // Iterate through the radices.
            foreach( int radix in
 radices )
            {
                // Convert a value with a radix.
                string valueString = 
                    Convert.ToString( value, radix );

                Console.WriteLine( "{0,8}  {1,3}    {2}", 
                    value, radix, valueString );
            }
        }
    } 

    static void Main( )
    {
        Console.WriteLine(
            "This example of Convert.ToString( short, int
 ) " +
            "generates \nthe following output. It converts several " +
            "short values to \nstrings using the radixes
 supported " +
            "by the method." );
        Console.WriteLine( 
            "\n   Value  Radix  String" +
            "\n   -----  -----  ------" );

        RunToStringDemo( );
    } 
} 

/*
This example of Convert.ToString( short, int ) generates
the following output. It converts several short values to
strings using the radixes supported by the method.

   Value  Radix  String
   -----  -----  ------
  -32768    2    1000000000000000
  -32768    8    100000
  -32768   10    -32768
  -32768   16    8000
    -100    2    1111111110011100
    -100    8    177634
    -100   10    -100
    -100   16    ff9c
     999    2    1111100111
     999    8    1747
     999   10    999
     999   16    3e7
   32767    2    111111111111111
   32767    8    77777
   32767   10    32767
   32767   16    7fff
*/
// Example of the Convert::ToString( short, int ) method.
using namespace System;
using namespace System::Collections;
void RunToStringDemo()
{
   array<short>^values = {Int16::MinValue, -100,999,Int16::MaxValue};
   int radices[4] = {2,8,10,16};
   
   // Implement foreach( short value in values ).
   IEnumerator^ myEnum = values->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      short value = Convert::ToInt16( myEnum->Current );
      
      // Iterate through the radices.
      for ( int i = 0; i < 4; i++ )
      {
         
         // Convert a value with a radix.
         int radix = radices[ i ];
         String^ valueString = Convert::ToString( value, radix );
         Console::WriteLine( "{0,8}  {1,3}    {2}", value, radix, valueString
 );

      }
   }
}

int main()
{
   Console::WriteLine( "This example of Convert::ToString( short, int
 ) "
   "generates \nthe following output. It converts several "
   "short values to \nstrings using the radixes supported
 "
   "by the method." );
   Console::WriteLine( "\n   Value  Radix  String"
   "\n   -----  -----  ------" );
   RunToStringDemo();
}

/*
This example of Convert::ToString( short, int ) generates
the following output. It converts several short values to
strings using the radixes supported by the method.

   Value  Radix  String
   -----  -----  ------
  -32768    2    1000000000000000
  -32768    8    100000
  -32768   10    -32768
  -32768   16    8000
    -100    2    1111111110011100
    -100    8    177634
    -100   10    -100
    -100   16    ff9c
     999    2    1111100111
     999    8    1747
     999   10    999
     999   16    3e7
   32767    2    111111111111111
   32767    8    77777
   32767   10    32767
   32767   16    7fff
*/
// Example of the Convert.ToString( short, int ) method.
import System.* ;

class ConvertRadixShortDemo
{   
    static void RunToStringDemo() 
    {
        short values[] =  { -32768, -100, 999, 32767 };
        int radices[] =  { 2, 8, 10, 16 };
        // Iterate through the values array.
        for (int iCtr = 0; iCtr < values.length;
 iCtr++) {
            short value = values[iCtr];
            // Iterate through the radices.
            for (int iCtr1 = 0 ; iCtr1 <
 radices.length ; iCtr1++) {
                int radix = radices[iCtr1];
                  // Convert a value with a radix.
                String valueString = Convert.ToString(value, radix);
                Console.WriteLine("{0,8}  {1,3}    {2}",
                    System.Convert.ToString(value),
                    System.Convert.ToString(radix), valueString);
            }
        }
    } //RunToStringDemo   
   
    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of Convert.ToString( short, int
 ) "
            + "generates \nthe following output. It converts several "
 
            + "short values to \nstrings using the radixes
 supported " 
            + "by the method."));
        Console.WriteLine(("\n   Value  Radix  String" 
            + "\n   -----  -----  ------"));
        RunToStringDemo();
    } //main
} //ConvertRadixShortDemo

/*
This example of Convert.ToString( short, int ) generates
the following output. It converts several short values to
strings using the radixes supported by the method.

   Value  Radix  String
   -----  -----  ------
  -32768    2    1000000000000000
  -32768    8    100000
  -32768   10    -32768
  -32768   16    8000
    -100    2    1111111110011100
    -100    8    177634
    -100   10    -100
    -100   16    ff9c
     999    2    1111100111
     999    8    1747
     999   10    999
     999   16    3e7
   32767    2    111111111111111
   32767    8    77777
   32767   10    32767
   32767   16    7fff
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (DateTime)

指定した DateTime の値を、それと等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

この実装は、DateTime.ToString と同じです。

使用例使用例

既定書式設定使用しToString メソッドDateTime の値を String変換するコード例次に示します

' Example of the Convert.ToString( DateTime ) and 
' Convert.ToString( DateTime, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module DateTimeIFormatProviderDemo
    
    Sub DisplayDateNCultureName( testDate As
 DateTime, _
        cultureName as String )

        ' Create the CultureInfo object for the specified culture,
        ' and use it as the IFormatProvider when converting the date.
        Dim culture  As CultureInfo = new
 CultureInfo( cultureName )
        Dim dateString As String
 = _
            Convert.ToString( testDate, culture )

        ' Bracket the culture name, and display the name and date.
        Console.WriteLine( "   {0,-12}{1}", _
            String.Concat( "[",
 cultureName, "]" ), dateString )
    End Sub

    Sub Main( )
        ' Specify the date to be formatted under various cultures.
        Dim tDate As DateTime = _
            new DateTime( 2003, 4, 15, 20, 30, 40, 333 )

        Console.WriteLine( "This example of " &
 vbCrLf & _
            "   Convert.ToString( DateTime ) and "
 & vbCrLf & _
            "   Convert.ToString( DateTime, IFormatProvider )"
 & _
            vbCrLf & "generates the following output. It "
 & _
            "creates CultureInfo objects " & vbCrLf
 & "for " & _
            "several cultures and formats " &
 _
            "a DateTime value with each." & vbCrLf
 )

        ' Format the date without an IFormatProvider.
        Console.WriteLine( "   {0,-12}{1}", _
            Nothing, "No IFormatProvider"
 )
        Console.WriteLine( "   {0,-12}{1}", _
            Nothing, "------------------"
 )
        Console.WriteLine( "   {0,-12}{1}" & vbCrLf,
 _
            String.Concat( _
                "[", CultureInfo.CurrentCulture.Name,
 "]" ), _
            Convert.ToString( tDate ) )

        ' Format the date with IFormatProvider for several cultures.
        Console.WriteLine( "   {0,-12}{1}", _
            "Culture", "With IFormatProvider"
 )
        Console.WriteLine( "   {0,-12}{1}", _
            "-------", "--------------------"
 )
        
        DisplayDateNCultureName( tDate, "" )
        DisplayDateNCultureName( tDate, "en-US" )
        DisplayDateNCultureName( tDate, "es-AR" )
        DisplayDateNCultureName( tDate, "fr-FR" )
        DisplayDateNCultureName( tDate, "hi-IN" )
        DisplayDateNCultureName( tDate, "ja-JP" )
        DisplayDateNCultureName( tDate, "nl-NL" )
        DisplayDateNCultureName( tDate, "ru-RU" )
        DisplayDateNCultureName( tDate, "ur-PK" )
    End Sub 
End Module 

' This example of
'    Convert.ToString( DateTime ) and
'    Convert.ToString( DateTime, IFormatProvider )
' generates the following output. It creates CultureInfo objects
' for several cultures and formats a DateTime value with each.
' 
'                No IFormatProvider
'                ------------------
'    [en-US]     4/15/2003 8:30:40 PM
' 
'    Culture     With IFormatProvider
'    -------     --------------------
'    []          04/15/2003 20:30:40
'    [en-US]     4/15/2003 8:30:40 PM
'    [es-AR]     15/04/2003 08:30:40 p.m.
'    [fr-FR]     15/04/2003 20:30:40
'    [hi-IN]     15-04-2003 20:30:40
'    [ja-JP]     2003/04/15 20:30:40
'    [nl-NL]     15-4-2003 20:30:40
'    [ru-RU]     15.04.2003 20:30:40
'    [ur-PK]     15/04/2003 8:30:40 PM
// Example of the Convert.ToString( DateTime ) and 
// Convert.ToString( DateTime, IFormatProvider ) methods.
using System;
using System.Globalization;

class DateTimeIFormatProviderDemo
{
    static void DisplayDateNCultureName( DateTime
 testDate, 
        string cultureName )
    {
        // Create the CultureInfo object for the specified culture,
        // and use it as the IFormatProvider when converting the date.
        CultureInfo culture = new CultureInfo( cultureName );
        string      dateString = Convert.ToString( testDate, culture
 );

        // Bracket the culture name, and display the name and date.
        Console.WriteLine("   {0,-12}{1}", 
            String.Concat( "[", cultureName, "]" ), dateString
 );
    }

    static void Main( )
    {
        // Specify the date to be formatted under various cultures.
        DateTime tDate = new DateTime( 2003, 4, 15, 20, 30, 40,
 333 );

        Console.WriteLine( "This example of \n" +
            "   Convert.ToString( DateTime ) and \n" +
            "   Convert.ToString( DateTime, IFormatProvider )\n" +
            "generates the following output. It creates " +
            "CultureInfo objects \nfor several cultures " +
            "and formats a DateTime value with each.\n" );

        // Format the date without an IFormatProvider.
        Console.WriteLine( "   {0,-12}{1}", 
            null, "No IFormatProvider" );
        Console.WriteLine( "   {0,-12}{1}", 
            null, "------------------" );
        Console.WriteLine( "   {0,-12}{1}\n", 
            String.Concat( "[", CultureInfo.CurrentCulture.Name, "]"
 ), 
            Convert.ToString( tDate ) );

        // Format the date with IFormatProvider for several cultures.
        Console.WriteLine( "   {0,-12}{1}", 
            "Culture", "With IFormatProvider" );
        Console.WriteLine( "   {0,-12}{1}", 
            "-------", "--------------------" );
        
        DisplayDateNCultureName( tDate, "" );
        DisplayDateNCultureName( tDate, "en-US" );
        DisplayDateNCultureName( tDate, "es-AR" );
        DisplayDateNCultureName( tDate, "fr-FR" );
        DisplayDateNCultureName( tDate, "hi-IN" );
        DisplayDateNCultureName( tDate, "ja-JP" );
        DisplayDateNCultureName( tDate, "nl-NL" );
        DisplayDateNCultureName( tDate, "ru-RU" );
        DisplayDateNCultureName( tDate, "ur-PK" );
    }
}

/*
This example of
   Convert.ToString( DateTime ) and
   Convert.ToString( DateTime, IFormatProvider )
generates the following output. It creates CultureInfo objects
for several cultures and formats a DateTime value with each.

               No IFormatProvider
               ------------------
   [en-US]     4/15/2003 8:30:40 PM

   Culture     With IFormatProvider
   -------     --------------------
   []          04/15/2003 20:30:40
   [en-US]     4/15/2003 8:30:40 PM
   [es-AR]     15/04/2003 08:30:40 p.m.
   [fr-FR]     15/04/2003 20:30:40
   [hi-IN]     15-04-2003 20:30:40
   [ja-JP]     2003/04/15 20:30:40
   [nl-NL]     15-4-2003 20:30:40
   [ru-RU]     15.04.2003 20:30:40
   [ur-PK]     15/04/2003 8:30:40 PM
*/ 
// Example of the Convert::ToString( DateTime ) and 
// Convert::ToString( DateTime, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;

#define null (Object^)0
void DisplayDateNCultureName( DateTime testDate, String^ cultureName
 )
{
   // Create the CultureInfo object for the specified culture,
   // and use it as the IFormatProvider when converting the date.
   CultureInfo^ culture = gcnew CultureInfo( cultureName );
   String^ dateString = Convert::ToString( testDate, culture );

   // Bracket the culture name, and display the name and date.
   Console::WriteLine( "   {0,-12}{1}", String::Concat( "[",
 cultureName, "]" ), dateString );
}

int main()
{
   // Specify the date to be formatted under various cultures.
   DateTime tDate = DateTime(2003,4,15,20,30,40,333);
   Console::WriteLine( "This example of \n"
   "   Convert::ToString( DateTime ) and \n"
   "   Convert::ToString( DateTime, IFormatProvider* )\n"
   "generates the following output. It creates "
   "CultureInfo objects \nfor several cultures "
   "and formats a DateTime value with each.\n" );

   // Format the date without an IFormatProvider.
   Console::WriteLine( "   {0,-12}{1}", null, "No
 IFormatProvider" );
   Console::WriteLine( "   {0,-12}{1}", null, "------------------"
 );
   Console::WriteLine( "   {0,-12}{1}\n", String::Concat( "[",
 CultureInfo::CurrentCulture->Name, "]" ), Convert::ToString( tDate
 ) );

   // Format the date with IFormatProvider for several cultures.
   Console::WriteLine( "   {0,-12}{1}", "Culture", "With
 IFormatProvider" );
   Console::WriteLine( "   {0,-12}{1}", "-------", "--------------------"
 );
   DisplayDateNCultureName( tDate, "" );
   DisplayDateNCultureName( tDate, "en-US" );
   DisplayDateNCultureName( tDate, "es-AR" );
   DisplayDateNCultureName( tDate, "fr-FR" );
   DisplayDateNCultureName( tDate, "hi-IN" );
   DisplayDateNCultureName( tDate, "ja-JP" );
   DisplayDateNCultureName( tDate, "nl-NL" );
   DisplayDateNCultureName( tDate, "ru-RU" );
   DisplayDateNCultureName( tDate, "ur-PK" );
}

/*
This example of
   Convert::ToString( DateTime ) and
   Convert::ToString( DateTime, IFormatProvider* )
generates the following output. It creates CultureInfo objects
for several cultures and formats a DateTime value with each.

               No IFormatProvider
               ------------------
   [en-US]     4/15/2003 8:30:40 PM

   Culture     With IFormatProvider
   -------     --------------------
   []          04/15/2003 20:30:40
   [en-US]     4/15/2003 8:30:40 PM
   [es-AR]     15/04/2003 08:30:40 p.m.
   [fr-FR]     15/04/2003 20:30:40
   [hi-IN]     15-04-2003 20:30:40
   [ja-JP]     2003/04/15 20:30:40
   [nl-NL]     15-4-2003 20:30:40
   [ru-RU]     15.04.2003 20:30:40
   [ur-PK]     15/04/2003 8:30:40 PM
*/
// Example of the Convert.ToString( DateTime ) and 
// Convert.ToString( DateTime, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class DateTimeIFormatProviderDemo
{   
    static void DisplayDateNCultureName(DateTime
 testDate, String cultureName) 
    {
        // Create the CultureInfo object for the specified culture,
        // and use it as the IFormatProvider when converting the date.
        CultureInfo culture =  new CultureInfo(cultureName);
        String dateString = Convert.ToString(testDate, culture);
      
        // Bracket the culture name, and display the name and date.
        Console.WriteLine("   {0,-12}{1}", String.Concat("[",
 cultureName, "]"), 
            dateString);
    } //DisplayDateNCultureName   
   
    public static void main(String[]
 args)
    {
   
        // Specify the date to be formatted under various cultures.
        DateTime tDate =  new DateTime(2003, 4, 15, 20, 30, 40,
 333);
      
        Console.WriteLine(("This example of \n" 
            + "   Convert.ToString( DateTime ) and \n" 
            + "   Convert.ToString( DateTime, IFormatProvider )\n" 
            + "generates the following output. It creates " 
            + "CultureInfo objects \nfor several cultures " 
            + "and formats a DateTime value with each.\n"));
      
        // Format the date without an IFormatProvider.
        Console.WriteLine("   {0,-12}{1}", null, "No
 IFormatProvider");
        Console.WriteLine("   {0,-12}{1}", null, "------------------");
        Console.WriteLine("   {0,-12}{1}\n", String.Concat("[",
 
            CultureInfo.get_CurrentCulture().get_Name(), "]"), 
            Convert.ToString(tDate));
      
        // Format the date with IFormatProvider for several cultures.
        Console.WriteLine("   {0,-12}{1}", "Culture", "With
 IFormatProvider");
        Console.WriteLine("   {0,-12}{1}", "-------", "--------------------");
      
        DisplayDateNCultureName(tDate, "");
        DisplayDateNCultureName(tDate, "en-US");
        DisplayDateNCultureName(tDate, "es-AR");
        DisplayDateNCultureName(tDate, "fr-FR");
        DisplayDateNCultureName(tDate, "hi-IN");
        DisplayDateNCultureName(tDate, "ja-JP");
        DisplayDateNCultureName(tDate, "nl-NL");
        DisplayDateNCultureName(tDate, "ru-RU");
        DisplayDateNCultureName(tDate, "ur-PK");
    } //main
} //DateTimeIFormatProviderDemo

/*
This example of
   Convert.ToString( DateTime ) and
   Convert.ToString( DateTime, IFormatProvider )
generates the following output. It creates CultureInfo objects
for several cultures and formats a DateTime value with each.

               No IFormatProvider
               ------------------
   [en-US]     4/15/2003 8:30:40 PM

   Culture     With IFormatProvider
   -------     --------------------
   []          04/15/2003 20:30:40
   [en-US]     4/15/2003 8:30:40 PM
   [es-AR]     15/04/2003 08:30:40 p.m.
   [fr-FR]     15/04/2003 20:30:40
   [hi-IN]     15-04-2003 20:30:40
   [ja-JP]     2003/04/15 20:30:40
   [nl-NL]     15-4-2003 20:30:40
   [ru-RU]     15.04.2003 20:30:40
   [ur-PK]     15/04/2003 8:30:40 PM
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (SByte)

指定した 8 ビット符号付き整数の値を等価String 形式変換します

このメソッドは、CLS準拠していません。  

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
Public Shared Function ToString
 ( _
    value As SByte _
) As String
[CLSCompliantAttribute(false)] 
public static string ToString
 (
    sbyte value
)
[CLSCompliantAttribute(false)] 
public:
static String^ ToString (
    signed char value
)
/** @attribute CLSCompliantAttribute(false) */ 
public static String ToString (
    SByte value
)
CLSCompliantAttribute(false) 
public static function ToString
 (
    value : sbyte
) : String

パラメータ

value

8 ビット符号付き整数

戻り値
value の値と等価String

解説解説

この実装は、SByte.ToString と同じです。

使用例使用例

既定書式設定使用しToString メソッドで SByte (符号付きバイト) 値を String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Double)

指定した倍精度浮動小数点数値を、それと等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

この実装は、Double.ToString と同じです。

使用例使用例

ToString使用してDoubleString変換する方法については、次のコード例参照してください

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
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 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}"
, 
        System.Convert.ToString(doubleVal), stringVal);
    try {        
        doubleVal = System.Convert.ToDouble(stringVal);
        System.Console.WriteLine("{0} as a double is: {1}", stringVal,
 
            System.Convert.ToString(doubleVal));
    }
    catch (System.OverflowException exp) {        
        System.Console.WriteLine(
            "Conversion from string-to-double overflowed.");
    }
    catch (System.FormatException exp) {        
        System.Console.WriteLine(
            "The string was not formatted as a double.");
    }
    catch (System.ArgumentException exp) {        
        System.Console.WriteLine("The string pointed to null.");
    }
} //ConvertDoubleString
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Int64)

指定した 64 ビット符号付き整数の値を等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

この実装は、Int64.ToString と同じです。

使用例使用例

既定書式設定使用してToString メソッド64 ビット整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Int16)

指定した 16 ビット符号付き整数の値を等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

この実装は、Int16.ToString と同じです。

使用例使用例

既定書式設定使用してToString メソッド16 ビット整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド


オーバーロードの一覧オーバーロードの一覧

名前 説明
Convert.ToString () 現在の Object を表す String返します
Convert.ToString (Boolean)  
Convert.ToString (Double)  
Convert.ToString (Object, Boolean)  
参照参照

Convert.ToString メソッド (Boolean, IFormatProvider)

指定したブール値を、それと等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Boolean, _
    provider As IFormatProvider _
) As String
public static string ToString
 (
    bool value,
    IFormatProvider provider
)
public:
static String^ ToString (
    bool value, 
    IFormatProvider^ provider
)
public static String ToString (
    boolean value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : boolean, 
    provider : IFormatProvider
) : String

パラメータ

value

ブール値。

provider

(予約済み) IFormatProvider インターフェイス実装インスタンス

戻り値
value の値と等価String

解説解説

この実装は、Boolean.ToString と同じです。

使用例使用例

目的書式プロバイダの型を表示する IFormatProvider オブジェクト使用しToString メソッドBoolean の値を String変換するコード例次に示しますIFormatProvider オブジェクト参照されないことを示す例です。

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

' 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
// 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
 ).
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 ).
import System.* ;
import 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 Object GetFormat(Type argType) 
    {
        // Here, the type of argType is displayed, and GetFormat
        // always returns Nothing.
        Console.Write("{0,-40}", argType.ToString());
        return null ;
    } //GetFormat
} //DummyProvider

class ConvertNonNumericProviderDemo
{   
    public static void main(String[]
 args)
    {  
        // 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 = (System.Double)(-98765.4321);
        DateTime dayTimeA =  new DateTime(2001, 9, 11, 13, 45,
 0);
      
        boolean 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);
    } //main
} //ConvertNonNumericProviderDemo

/*
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@33c0d9d

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Int32, Int32)

32 ビット符号付き整数の値を、指定した基数等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Integer, _
    toBase As Integer _
) As String
Dim value As Integer
Dim toBase As Integer
Dim returnValue As String

returnValue = Convert.ToString(value, toBase)
public static string ToString
 (
    int value,
    int toBase
)
public:
static String^ ToString (
    int value, 
    int toBase
)
public static String ToString (
    int value, 
    int toBase
)
public static function ToString
 (
    value : int, 
    toBase : int
) : String

パラメータ

value

32 ビット符号付き整数

toBase

戻り値基数。これは 2、8、10、または 16 である必要があります

戻り値
基数 toBase での valueString 形式

例外例外
例外種類条件

ArgumentException

toBase が 2、8、10、または 16 ではありません。

使用例使用例

ToString メソッド使用して、このメソッドサポートする基数に従って複数32 ビット整数String変換するコード例次に示します

' Example of the Convert.ToString( Integer, Integer ) method.
Imports System
Imports Microsoft.VisualBasic

Module ConvertRadixIntDemo
    
    Sub RunToStringDemo( )

        Dim values as Integer(
 ) = { _
            Integer.MinValue, _
            -100, _
            0, _
            99999, _
            Integer.MaxValue }
        Dim radices as Integer(
 ) = { 2, 8, 10, 16 }

        ' Iterate through the values array.
        Dim value as Integer
        For Each value in
 values

            ' Iterate through the radices.
            Dim radix as Integer
            For Each radix in
 radices

                ' Convert a value with a radix.
                Dim valueString As String
 = _
                    Convert.ToString( value, radix )

                Console.WriteLine( "{0,13}  {1,3}    {2}",
 _
                    value, radix, valueString )
            Next radix
        Next value
    End Sub 

    Sub Main( )

        Console.WriteLine( _
            "This example of Convert.ToString( Integer, Integer
 " & _ 
            ") generates " & vbCrLf & "the
 following output. It " & _
            "converts several Integer values to "
 & vbCrLf & _
            "strings using the radixes supported by the method."
 ) 
        Console.WriteLine( vbCrLf & _
            "     Value     Radix    String" &
 vbCrLf & _
            "     -----     -----    ------" )

        RunToStringDemo( )

    End Sub 
End Module 

' This example of Convert.ToString( Integer, Integer ) generates
' the following output. It converts several Integer values to
' strings using the radixes supported by the method.
' 
'      Value     Radix    String
'      -----     -----    ------
'   -2147483648    2    10000000000000000000000000000000
'   -2147483648    8    20000000000
'   -2147483648   10    -2147483648
'   -2147483648   16    80000000
'          -100    2    11111111111111111111111110011100
'          -100    8    37777777634
'          -100   10    -100
'          -100   16    ffffff9c
'             0    2    0
'             0    8    0
'             0   10    0
'             0   16    0
'         99999    2    11000011010011111
'         99999    8    303237
'         99999   10    99999
'         99999   16    1869f
'    2147483647    2    1111111111111111111111111111111
'    2147483647    8    17777777777
'    2147483647   10    2147483647
'    2147483647   16    7fffffff
// Example of the Convert.ToString( int, int ) method.
using System;

class ConvertRadixIntDemo
{
    static void RunToStringDemo( )
    {
        int[ ] values = {
            int.MinValue, 
            -100, 
            0, 
            99999, 
            int.MaxValue };
        int[ ]  radices = { 2, 8, 10, 16 };

        // Iterate through the values array.
        foreach( int value in
 values )
        {
            // Iterate through the radices.
            foreach( int radix in
 radices )
            {
                // Convert a value with a radix.
                string valueString = 
                    Convert.ToString( value, radix );

                Console.WriteLine( "{0,13}  {1,3}    {2}", 
                    value, radix, valueString );
            }
        }
    } 

    static void Main( )
    {
        Console.WriteLine(
            "This example of Convert.ToString( int, int
 ) " +
            "generates \nthe following output. It converts several " +
            "int values to \nstrings using
 the radixes supported " +
            "by the method." );
        Console.WriteLine( 
            "\n     Value     Radix    String" +
            "\n     -----     -----    ------" );

        RunToStringDemo( );
    } 
} 

/*
This example of Convert.ToString( int, int
 ) generates
the following output. It converts several int values to
strings using the radixes supported by the method.

     Value     Radix    String
     -----     -----    ------
  -2147483648    2    10000000000000000000000000000000
  -2147483648    8    20000000000
  -2147483648   10    -2147483648
  -2147483648   16    80000000
         -100    2    11111111111111111111111110011100
         -100    8    37777777634
         -100   10    -100
         -100   16    ffffff9c
            0    2    0
            0    8    0
            0   10    0
            0   16    0
        99999    2    11000011010011111
        99999    8    303237
        99999   10    99999
        99999   16    1869f
   2147483647    2    1111111111111111111111111111111
   2147483647    8    17777777777
   2147483647   10    2147483647
   2147483647   16    7fffffff
*/
// Example of the Convert::ToString( int, int ) method.
using namespace System;
using namespace System::Collections;
void RunToStringDemo()
{
   array<int>^values = {Int32::MinValue, -100,0,99999,Int32::MaxValue};
   int radices[4] = {2,8,10,16};
   
   // Implement foreach( int value in values ).
   IEnumerator^ myEnum = values->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      int value = Convert::ToInt32( myEnum->Current );
      
      // Iterate through the radices.
      for ( int i = 0; i < 4; i++ )
      {
         
         // Convert a value with a radix.
         int radix = radices[ i ];
         String^ valueString = Convert::ToString( value, radix );
         Console::WriteLine( "{0,12} {1,3}   {2}", value, radix, valueString
 );

      }
   }
}

int main()
{
   Console::WriteLine( "This example of Convert::ToString( int,
 int ) "
   "generates \nthe following output. It converts several "
   "int values to \nstrings using the
 radixes supported "
   "by the method." );
   Console::WriteLine( "\n    Value    Radix   String"
   "\n    -----    -----   ------" );
   RunToStringDemo();
}

/*
This example of Convert::ToString( int, int
 ) generates
the following output. It converts several int values to
strings using the radixes supported by the method.

    Value    Radix   String
    -----    -----   ------
 -2147483648   2   10000000000000000000000000000000
 -2147483648   8   20000000000
 -2147483648  10   -2147483648
 -2147483648  16   80000000
        -100   2   11111111111111111111111110011100
        -100   8   37777777634
        -100  10   -100
        -100  16   ffffff9c
           0   2   0
           0   8   0
           0  10   0
           0  16   0
       99999   2   11000011010011111
       99999   8   303237
       99999  10   99999
       99999  16   1869f
  2147483647   2   1111111111111111111111111111111
  2147483647   8   17777777777
  2147483647  10   2147483647
  2147483647  16   7fffffff
*/
// Example of the Convert.ToString( int, int ) method.
import System.* ;

class ConvertRadixIntDemo
{   
    static void RunToStringDemo() 
    {
        int values[] =  { -2147483648, -100, 0, 99999, 2147483647
 };
        int radices[] =  { 2, 8, 10, 16 };
        // Iterate through the values array.
        for(int iCtr=0; iCtr < values.length;
 iCtr++) {
            int value = values[iCtr];
      
            // Iterate through the radices.
            for(int iCtr1=0; iCtr1<radices.length;
 iCtr1++) {
                int radix = radices[iCtr1];
                // Convert a value with a radix.
                String valueString = Convert.ToString(value, radix);
                Console.WriteLine("{0,13}  {1,3}    {2}",
                    System.Convert.ToString(value),
                    System.Convert.ToString(radix), valueString);
            }
        }
    } //RunToStringDemo   
   
   public static void main(String[]
 args)
   {
        Console.WriteLine(("This example of Convert.ToString( int,
 int ) " 
            + "generates \nthe following output. It converts several "
 
            + "int values to \nstrings using
 the radixes supported " 
            + "by the method."));
        Console.WriteLine(("\n     Value     Radix    String" 
            + "\n     -----     -----    ------"));
      
        RunToStringDemo();
   } //main
} //ConvertRadixIntDemo

/*
This example of Convert.ToString( int, int
 ) generates
the following output. It converts several int values to
strings using the radixes supported by the method.

     Value     Radix    String
     -----     -----    ------
  -2147483648    2    10000000000000000000000000000000
  -2147483648    8    20000000000
  -2147483648   10    -2147483648
  -2147483648   16    80000000
         -100    2    11111111111111111111111110011100
         -100    8    37777777634
         -100   10    -100
         -100   16    ffffff9c
            0    2    0
            0    8    0
            0   10    0
            0   16    0
        99999    2    11000011010011111
        99999    8    303237
        99999   10    99999
        99999   16    1869f
   2147483647    2    1111111111111111111111111111111
   2147483647    8    17777777777
   2147483647   10    2147483647
   2147483647   16    7fffffff
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Byte, IFormatProvider)

指定した 8 ビット符号なし整数の値を等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Byte, _
    provider As IFormatProvider _
) As String
Dim value As Byte
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
public static string ToString
 (
    byte value,
    IFormatProvider provider
)
public:
static String^ ToString (
    unsigned char value, 
    IFormatProvider^ provider
)
public static String ToString (
    byte value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : byte, 
    provider : IFormatProvider
) : String

パラメータ

value

8 ビット符号なし整数

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、Byte.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用しToString メソッドByte符号なし値を String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Char, IFormatProvider)

指定した Unicode 文字の値を、それと等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Char, _
    provider As IFormatProvider _
) As String
Dim value As Char
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
public static string ToString
 (
    char value,
    IFormatProvider provider
)
public:
static String^ ToString (
    wchar_t value, 
    IFormatProvider^ provider
)
public static String ToString (
    char value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : char, 
    provider : IFormatProvider
) : String

パラメータ

value

Unicode 文字

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、Char.ToString と同じです。

使用例使用例

目的書式プロバイダの型を表示する IFormatProvider オブジェクト使用しToString メソッドChar の値を String変換するコード例次に示しますIFormatProvider オブジェクト参照されないことを示す例です。

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

' 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
// 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
 ).
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 ).
import System.* ;
import 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 Object GetFormat(Type argType) 
    {
        // Here, the type of argType is displayed, and GetFormat
        // always returns Nothing.
        Console.Write("{0,-40}", argType.ToString());
        return null ;
    } //GetFormat
} //DummyProvider

class ConvertNonNumericProviderDemo
{   
    public static void main(String[]
 args)
    {  
        // 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 = (System.Double)(-98765.4321);
        DateTime dayTimeA =  new DateTime(2001, 9, 11, 13, 45,
 0);
      
        boolean 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);
    } //main
} //ConvertNonNumericProviderDemo

/*
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@33c0d9d

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (DateTime, IFormatProvider)

指定した DateTime の値を、それと等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As DateTime, _
    provider As IFormatProvider _
) As String
public static string ToString
 (
    DateTime value,
    IFormatProvider provider
)
public:
static String^ ToString (
    DateTime value, 
    IFormatProvider^ provider
)
public static String ToString (
    DateTime value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : DateTime, 
    provider : IFormatProvider
) : String

パラメータ

value

DateTime

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、DateTime.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用しToString メソッドDateTime の値を String変換するコード例次に示します

' Example of the Convert.ToString( DateTime ) and 
' Convert.ToString( DateTime, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module DateTimeIFormatProviderDemo
    
    Sub DisplayDateNCultureName( testDate As
 DateTime, _
        cultureName as String )

        ' Create the CultureInfo object for the specified culture,
        ' and use it as the IFormatProvider when converting the date.
        Dim culture  As CultureInfo = new
 CultureInfo( cultureName )
        Dim dateString As String
 = _
            Convert.ToString( testDate, culture )

        ' Bracket the culture name, and display the name and date.
        Console.WriteLine( "   {0,-12}{1}", _
            String.Concat( "[",
 cultureName, "]" ), dateString )
    End Sub

    Sub Main( )
        ' Specify the date to be formatted under various cultures.
        Dim tDate As DateTime = _
            new DateTime( 2003, 4, 15, 20, 30, 40, 333 )

        Console.WriteLine( "This example of " &
 vbCrLf & _
            "   Convert.ToString( DateTime ) and "
 & vbCrLf & _
            "   Convert.ToString( DateTime, IFormatProvider )"
 & _
            vbCrLf & "generates the following output. It "
 & _
            "creates CultureInfo objects " & vbCrLf
 & "for " & _
            "several cultures and formats " &
 _
            "a DateTime value with each." & vbCrLf
 )

        ' Format the date without an IFormatProvider.
        Console.WriteLine( "   {0,-12}{1}", _
            Nothing, "No IFormatProvider"
 )
        Console.WriteLine( "   {0,-12}{1}", _
            Nothing, "------------------"
 )
        Console.WriteLine( "   {0,-12}{1}" & vbCrLf,
 _
            String.Concat( _
                "[", CultureInfo.CurrentCulture.Name,
 "]" ), _
            Convert.ToString( tDate ) )

        ' Format the date with IFormatProvider for several cultures.
        Console.WriteLine( "   {0,-12}{1}", _
            "Culture", "With IFormatProvider"
 )
        Console.WriteLine( "   {0,-12}{1}", _
            "-------", "--------------------"
 )
        
        DisplayDateNCultureName( tDate, "" )
        DisplayDateNCultureName( tDate, "en-US" )
        DisplayDateNCultureName( tDate, "es-AR" )
        DisplayDateNCultureName( tDate, "fr-FR" )
        DisplayDateNCultureName( tDate, "hi-IN" )
        DisplayDateNCultureName( tDate, "ja-JP" )
        DisplayDateNCultureName( tDate, "nl-NL" )
        DisplayDateNCultureName( tDate, "ru-RU" )
        DisplayDateNCultureName( tDate, "ur-PK" )
    End Sub 
End Module 

' This example of
'    Convert.ToString( DateTime ) and
'    Convert.ToString( DateTime, IFormatProvider )
' generates the following output. It creates CultureInfo objects
' for several cultures and formats a DateTime value with each.
' 
'                No IFormatProvider
'                ------------------
'    [en-US]     4/15/2003 8:30:40 PM
' 
'    Culture     With IFormatProvider
'    -------     --------------------
'    []          04/15/2003 20:30:40
'    [en-US]     4/15/2003 8:30:40 PM
'    [es-AR]     15/04/2003 08:30:40 p.m.
'    [fr-FR]     15/04/2003 20:30:40
'    [hi-IN]     15-04-2003 20:30:40
'    [ja-JP]     2003/04/15 20:30:40
'    [nl-NL]     15-4-2003 20:30:40
'    [ru-RU]     15.04.2003 20:30:40
'    [ur-PK]     15/04/2003 8:30:40 PM
// Example of the Convert.ToString( DateTime ) and 
// Convert.ToString( DateTime, IFormatProvider ) methods.
using System;
using System.Globalization;

class DateTimeIFormatProviderDemo
{
    static void DisplayDateNCultureName( DateTime
 testDate, 
        string cultureName )
    {
        // Create the CultureInfo object for the specified culture,
        // and use it as the IFormatProvider when converting the date.
        CultureInfo culture = new CultureInfo( cultureName );
        string      dateString = Convert.ToString( testDate, culture
 );

        // Bracket the culture name, and display the name and date.
        Console.WriteLine("   {0,-12}{1}", 
            String.Concat( "[", cultureName, "]" ), dateString
 );
    }

    static void Main( )
    {
        // Specify the date to be formatted under various cultures.
        DateTime tDate = new DateTime( 2003, 4, 15, 20, 30, 40,
 333 );

        Console.WriteLine( "This example of \n" +
            "   Convert.ToString( DateTime ) and \n" +
            "   Convert.ToString( DateTime, IFormatProvider )\n" +
            "generates the following output. It creates " +
            "CultureInfo objects \nfor several cultures " +
            "and formats a DateTime value with each.\n" );

        // Format the date without an IFormatProvider.
        Console.WriteLine( "   {0,-12}{1}", 
            null, "No IFormatProvider" );
        Console.WriteLine( "   {0,-12}{1}", 
            null, "------------------" );
        Console.WriteLine( "   {0,-12}{1}\n", 
            String.Concat( "[", CultureInfo.CurrentCulture.Name, "]"
 ), 
            Convert.ToString( tDate ) );

        // Format the date with IFormatProvider for several cultures.
        Console.WriteLine( "   {0,-12}{1}", 
            "Culture", "With IFormatProvider" );
        Console.WriteLine( "   {0,-12}{1}", 
            "-------", "--------------------" );
        
        DisplayDateNCultureName( tDate, "" );
        DisplayDateNCultureName( tDate, "en-US" );
        DisplayDateNCultureName( tDate, "es-AR" );
        DisplayDateNCultureName( tDate, "fr-FR" );
        DisplayDateNCultureName( tDate, "hi-IN" );
        DisplayDateNCultureName( tDate, "ja-JP" );
        DisplayDateNCultureName( tDate, "nl-NL" );
        DisplayDateNCultureName( tDate, "ru-RU" );
        DisplayDateNCultureName( tDate, "ur-PK" );
    }
}

/*
This example of
   Convert.ToString( DateTime ) and
   Convert.ToString( DateTime, IFormatProvider )
generates the following output. It creates CultureInfo objects
for several cultures and formats a DateTime value with each.

               No IFormatProvider
               ------------------
   [en-US]     4/15/2003 8:30:40 PM

   Culture     With IFormatProvider
   -------     --------------------
   []          04/15/2003 20:30:40
   [en-US]     4/15/2003 8:30:40 PM
   [es-AR]     15/04/2003 08:30:40 p.m.
   [fr-FR]     15/04/2003 20:30:40
   [hi-IN]     15-04-2003 20:30:40
   [ja-JP]     2003/04/15 20:30:40
   [nl-NL]     15-4-2003 20:30:40
   [ru-RU]     15.04.2003 20:30:40
   [ur-PK]     15/04/2003 8:30:40 PM
*/ 
// Example of the Convert::ToString( DateTime ) and 
// Convert::ToString( DateTime, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;

#define null (Object^)0
void DisplayDateNCultureName( DateTime testDate, String^ cultureName
 )
{
   // Create the CultureInfo object for the specified culture,
   // and use it as the IFormatProvider when converting the date.
   CultureInfo^ culture = gcnew CultureInfo( cultureName );
   String^ dateString = Convert::ToString( testDate, culture );

   // Bracket the culture name, and display the name and date.
   Console::WriteLine( "   {0,-12}{1}", String::Concat( "[",
 cultureName, "]" ), dateString );
}

int main()
{
   // Specify the date to be formatted under various cultures.
   DateTime tDate = DateTime(2003,4,15,20,30,40,333);
   Console::WriteLine( "This example of \n"
   "   Convert::ToString( DateTime ) and \n"
   "   Convert::ToString( DateTime, IFormatProvider* )\n"
   "generates the following output. It creates "
   "CultureInfo objects \nfor several cultures "
   "and formats a DateTime value with each.\n" );

   // Format the date without an IFormatProvider.
   Console::WriteLine( "   {0,-12}{1}", null, "No
 IFormatProvider" );
   Console::WriteLine( "   {0,-12}{1}", null, "------------------"
 );
   Console::WriteLine( "   {0,-12}{1}\n", String::Concat( "[",
 CultureInfo::CurrentCulture->Name, "]" ), Convert::ToString( tDate
 ) );

   // Format the date with IFormatProvider for several cultures.
   Console::WriteLine( "   {0,-12}{1}", "Culture", "With
 IFormatProvider" );
   Console::WriteLine( "   {0,-12}{1}", "-------", "--------------------"
 );
   DisplayDateNCultureName( tDate, "" );
   DisplayDateNCultureName( tDate, "en-US" );
   DisplayDateNCultureName( tDate, "es-AR" );
   DisplayDateNCultureName( tDate, "fr-FR" );
   DisplayDateNCultureName( tDate, "hi-IN" );
   DisplayDateNCultureName( tDate, "ja-JP" );
   DisplayDateNCultureName( tDate, "nl-NL" );
   DisplayDateNCultureName( tDate, "ru-RU" );
   DisplayDateNCultureName( tDate, "ur-PK" );
}

/*
This example of
   Convert::ToString( DateTime ) and
   Convert::ToString( DateTime, IFormatProvider* )
generates the following output. It creates CultureInfo objects
for several cultures and formats a DateTime value with each.

               No IFormatProvider
               ------------------
   [en-US]     4/15/2003 8:30:40 PM

   Culture     With IFormatProvider
   -------     --------------------
   []          04/15/2003 20:30:40
   [en-US]     4/15/2003 8:30:40 PM
   [es-AR]     15/04/2003 08:30:40 p.m.
   [fr-FR]     15/04/2003 20:30:40
   [hi-IN]     15-04-2003 20:30:40
   [ja-JP]     2003/04/15 20:30:40
   [nl-NL]     15-4-2003 20:30:40
   [ru-RU]     15.04.2003 20:30:40
   [ur-PK]     15/04/2003 8:30:40 PM
*/
// Example of the Convert.ToString( DateTime ) and 
// Convert.ToString( DateTime, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class DateTimeIFormatProviderDemo
{   
    static void DisplayDateNCultureName(DateTime
 testDate, String cultureName) 
    {
        // Create the CultureInfo object for the specified culture,
        // and use it as the IFormatProvider when converting the date.
        CultureInfo culture =  new CultureInfo(cultureName);
        String dateString = Convert.ToString(testDate, culture);
      
        // Bracket the culture name, and display the name and date.
        Console.WriteLine("   {0,-12}{1}", String.Concat("[",
 cultureName, "]"), 
            dateString);
    } //DisplayDateNCultureName   
   
    public static void main(String[]
 args)
    {
   
        // Specify the date to be formatted under various cultures.
        DateTime tDate =  new DateTime(2003, 4, 15, 20, 30, 40,
 333);
      
        Console.WriteLine(("This example of \n" 
            + "   Convert.ToString( DateTime ) and \n" 
            + "   Convert.ToString( DateTime, IFormatProvider )\n" 
            + "generates the following output. It creates " 
            + "CultureInfo objects \nfor several cultures " 
            + "and formats a DateTime value with each.\n"));
      
        // Format the date without an IFormatProvider.
        Console.WriteLine("   {0,-12}{1}", null, "No
 IFormatProvider");
        Console.WriteLine("   {0,-12}{1}", null, "------------------");
        Console.WriteLine("   {0,-12}{1}\n", String.Concat("[",
 
            CultureInfo.get_CurrentCulture().get_Name(), "]"), 
            Convert.ToString(tDate));
      
        // Format the date with IFormatProvider for several cultures.
        Console.WriteLine("   {0,-12}{1}", "Culture", "With
 IFormatProvider");
        Console.WriteLine("   {0,-12}{1}", "-------", "--------------------");
      
        DisplayDateNCultureName(tDate, "");
        DisplayDateNCultureName(tDate, "en-US");
        DisplayDateNCultureName(tDate, "es-AR");
        DisplayDateNCultureName(tDate, "fr-FR");
        DisplayDateNCultureName(tDate, "hi-IN");
        DisplayDateNCultureName(tDate, "ja-JP");
        DisplayDateNCultureName(tDate, "nl-NL");
        DisplayDateNCultureName(tDate, "ru-RU");
        DisplayDateNCultureName(tDate, "ur-PK");
    } //main
} //DateTimeIFormatProviderDemo

/*
This example of
   Convert.ToString( DateTime ) and
   Convert.ToString( DateTime, IFormatProvider )
generates the following output. It creates CultureInfo objects
for several cultures and formats a DateTime value with each.

               No IFormatProvider
               ------------------
   [en-US]     4/15/2003 8:30:40 PM

   Culture     With IFormatProvider
   -------     --------------------
   []          04/15/2003 20:30:40
   [en-US]     4/15/2003 8:30:40 PM
   [es-AR]     15/04/2003 08:30:40 p.m.
   [fr-FR]     15/04/2003 20:30:40
   [hi-IN]     15-04-2003 20:30:40
   [ja-JP]     2003/04/15 20:30:40
   [nl-NL]     15-4-2003 20:30:40
   [ru-RU]     15.04.2003 20:30:40
   [ur-PK]     15/04/2003 8:30:40 PM
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Decimal, IFormatProvider)

指定した Decimal数値を、それと等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Decimal, _
    provider As IFormatProvider _
) As String
public static string ToString
 (
    decimal value,
    IFormatProvider provider
)
public:
static String^ ToString (
    Decimal value, 
    IFormatProvider^ provider
)
public static String ToString (
    Decimal value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : decimal, 
    provider : IFormatProvider
) : String

パラメータ

value

Decimal数値

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、Decimal.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用しToString メソッドDecimal の値を String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Double, IFormatProvider)

指定した倍精度浮動小数点数値を、それと等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Double, _
    provider As IFormatProvider _
) As String
Dim value As Double
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
public static string ToString
 (
    double value,
    IFormatProvider provider
)
public:
static String^ ToString (
    double value, 
    IFormatProvider^ provider
)
public static String ToString (
    double value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : double, 
    provider : IFormatProvider
) : String

パラメータ

value

倍精度浮動小数点数

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価Stringprovider無視され、この操作には関与しません。

解説解説

この実装は、Double.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用しToString メソッドDouble の値を String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Int16, IFormatProvider)

指定した 16 ビット符号付き整数の値を等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Short, _
    provider As IFormatProvider _
) As String
Dim value As Short
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
public static string ToString
 (
    short value,
    IFormatProvider provider
)
public:
static String^ ToString (
    short value, 
    IFormatProvider^ provider
)
public static String ToString (
    short value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : short, 
    provider : IFormatProvider
) : String

パラメータ

value

16 ビット符号付き整数

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、Int16.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用してToString メソッド16 ビット整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Int32, IFormatProvider)

指定した 32 ビット符号付き整数の値を等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Integer, _
    provider As IFormatProvider _
) As String
public static string ToString
 (
    int value,
    IFormatProvider provider
)
public:
static String^ ToString (
    int value, 
    IFormatProvider^ provider
)
public static String ToString (
    int value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : int, 
    provider : IFormatProvider
) : String

パラメータ

value

32 ビット符号付き整数

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、Int32.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用してToString メソッド32 ビット整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Int64, IFormatProvider)

指定した 64 ビット符号付き整数の値を等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Long, _
    provider As IFormatProvider _
) As String
Dim value As Long
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
public static string ToString
 (
    long value,
    IFormatProvider provider
)
public:
static String^ ToString (
    long long value, 
    IFormatProvider^ provider
)
public static String ToString (
    long value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : long, 
    provider : IFormatProvider
) : String

パラメータ

value

64 ビット符号付き整数

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、Int64.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用してToString メソッド64 ビット整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Object, IFormatProvider)

指定したカルチャに固有の書式情報使用して指定した Object の値を、それと等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Object, _
    provider As IFormatProvider _
) As String
Dim value As Object
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
public static string ToString
 (
    Object value,
    IFormatProvider provider
)
public:
static String^ ToString (
    Object^ value, 
    IFormatProvider^ provider
)
public static String ToString (
    Object value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : Object, 
    provider : IFormatProvider
) : String

パラメータ

value

Object または null 参照 (Visual Basic では Nothing)。

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
String 形式での value の値。valuenull 参照 (Visual Basic では Nothing) の場合は String.Empty。

解説解説
使用例使用例

目的書式プロバイダの型を表示する IFormatProvider オブジェクト使用しToString メソッド数値以外の Objectボックス内の数値String変換するコード例次に示します数値以外の Object場合は、IFormatProvider オブジェクト参照されないことを示す例です。

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

' 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
// 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
 ).
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 ).
import System.* ;
import 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 Object GetFormat(Type argType) 
    {
        // Here, the type of argType is displayed, and GetFormat
        // always returns Nothing.
        Console.Write("{0,-40}", argType.ToString());
        return null ;
    } //GetFormat
} //DummyProvider

class ConvertNonNumericProviderDemo
{   
    public static void main(String[]
 args)
    {  
        // 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 = (System.Double)(-98765.4321);
        DateTime dayTimeA =  new DateTime(2001, 9, 11, 13, 45,
 0);
      
        boolean 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);
    } //main
} //ConvertNonNumericProviderDemo

/*
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@33c0d9d

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (SByte, IFormatProvider)

指定した 8 ビット符号付き整数の値を等価String 形式変換します

このメソッドは、CLS準拠していません。  

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
Public Shared Function ToString
 ( _
    value As SByte, _
    provider As IFormatProvider _
) As String
Dim value As SByte
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
[CLSCompliantAttribute(false)] 
public static string ToString
 (
    sbyte value,
    IFormatProvider provider
)
[CLSCompliantAttribute(false)] 
public:
static String^ ToString (
    signed char value, 
    IFormatProvider^ provider
)
/** @attribute CLSCompliantAttribute(false) */ 
public static String ToString (
    SByte value, 
    IFormatProvider provider
)
CLSCompliantAttribute(false) 
public static function ToString
 (
    value : sbyte, 
    provider : IFormatProvider
) : String

パラメータ

value

8 ビット符号付き整数

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、SByte.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用しToString メソッドで SByte (符号付きバイト) 値を String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (String)

指定した Stringインスタンス返します実際変換処理は実行されません。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

使用例使用例

ToString メソッドString 引数呼び出すと、String が未変更のまま返される場合コード例次に示します

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

' 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
// 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
 ).
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 ).
import System.* ;
import 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 Object GetFormat(Type argType) 
    {
        // Here, the type of argType is displayed, and GetFormat
        // always returns Nothing.
        Console.Write("{0,-40}", argType.ToString());
        return null ;
    } //GetFormat
} //DummyProvider

class ConvertNonNumericProviderDemo
{   
    public static void main(String[]
 args)
    {  
        // 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 = (System.Double)(-98765.4321);
        DateTime dayTimeA =  new DateTime(2001, 9, 11, 13, 45,
 0);
      
        boolean 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);
    } //main
} //ConvertNonNumericProviderDemo

/*
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@33c0d9d

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Single, IFormatProvider)

指定した単精度浮動小数点数値を等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Single, _
    provider As IFormatProvider _
) As String
Dim value As Single
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
public static string ToString
 (
    float value,
    IFormatProvider provider
)
public:
static String^ ToString (
    float value, 
    IFormatProvider^ provider
)
public static String ToString (
    float value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : float, 
    provider : IFormatProvider
) : String

パラメータ

value

単精度浮動小数点数

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、Single.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用しToString メソッドSingle の値を String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (String, IFormatProvider)

指定した Stringインスタンス返します実際変換処理は実行されません。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As String, _
    provider As IFormatProvider _
) As String
Dim value As String
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
public static string ToString
 (
    string value,
    IFormatProvider provider
)
public:
static String^ ToString (
    String^ value, 
    IFormatProvider^ provider
)
public static String ToString (
    String value, 
    IFormatProvider provider
)
public static function ToString
 (
    value : String, 
    provider : IFormatProvider
) : String

パラメータ

value

String

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
パラメータ value変更されずに返されます。

解説解説
使用例使用例

ToString メソッドString 引数呼び出すと、String が未変更のまま返されIFormatProvider オブジェクト参照されない場合コード例次に示します

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

' 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
// 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
 ).
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 ).
import System.* ;
import 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 Object GetFormat(Type argType) 
    {
        // Here, the type of argType is displayed, and GetFormat
        // always returns Nothing.
        Console.Write("{0,-40}", argType.ToString());
        return null ;
    } //GetFormat
} //DummyProvider

class ConvertNonNumericProviderDemo
{   
    public static void main(String[]
 args)
    {  
        // 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 = (System.Double)(-98765.4321);
        DateTime dayTimeA =  new DateTime(2001, 9, 11, 13, 45,
 0);
      
        boolean 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);
    } //main
} //ConvertNonNumericProviderDemo

/*
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@33c0d9d

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (UInt16, IFormatProvider)

指定した 16 ビット符号なし整数の値を等価String 形式変換します

このメソッドは、CLS準拠していません。  

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
Public Shared Function ToString
 ( _
    value As UShort, _
    provider As IFormatProvider _
) As String
Dim value As UShort
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
[CLSCompliantAttribute(false)] 
public static string ToString
 (
    ushort value,
    IFormatProvider provider
)
[CLSCompliantAttribute(false)] 
public:
static String^ ToString (
    unsigned short value, 
    IFormatProvider^ provider
)
/** @attribute CLSCompliantAttribute(false) */ 
public static String ToString (
    UInt16 value, 
    IFormatProvider provider
)
CLSCompliantAttribute(false) 
public static function ToString
 (
    value : ushort, 
    provider : IFormatProvider
) : String

パラメータ

value

16 ビット符号なし整数

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、UInt16.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用してToString メソッド16 ビット符号なし整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (UInt32, IFormatProvider)

指定した 32 ビット符号なし整数の値を等価String 形式変換します

このメソッドは、CLS準拠していません。  

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
Public Shared Function ToString
 ( _
    value As UInteger, _
    provider As IFormatProvider _
) As String
Dim value As UInteger
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
[CLSCompliantAttribute(false)] 
public static string ToString
 (
    uint value,
    IFormatProvider provider
)
[CLSCompliantAttribute(false)] 
public:
static String^ ToString (
    unsigned int value, 
    IFormatProvider^ provider
)
/** @attribute CLSCompliantAttribute(false) */ 
public static String ToString (
    UInt32 value, 
    IFormatProvider provider
)
CLSCompliantAttribute(false) 
public static function ToString
 (
    value : uint, 
    provider : IFormatProvider
) : String

パラメータ

value

32 ビット符号なし整数

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、UInt32.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用してToString メソッド32 ビット符号なし整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Single)

指定した単精度浮動小数点数値を等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

この実装は、Single.ToString と同じです。

使用例使用例

ToString使用してSingleString変換する方法については、次のコード例参照してください

Public Sub ConvertStringFloat(ByVal
 stringVal As String)
    Dim singleVal As Single
 = 0

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

    ' Single to string conversion will not overflow.
    stringVal = System.Convert.ToString(singleVal)
    System.Console.WriteLine("The single as a string is {0}.",
 _
                              stringVal)
End Sub
public void ConvertStringFloat(string
 stringVal) {
    float floatVal = 0;
    
    try {
        floatVal = System.Convert.ToSingle(stringVal);
        System.Console.WriteLine(
            "The string as a float is
 {0}.", floatVal);
    } 
    catch (System.OverflowException){
        System.Console.WriteLine(
            "The conversion from string-to-float
 overflowed.");
    }
    catch (System.FormatException) {
        System.Console.WriteLine(
            "The string is not formatted as a float.");
    }
    catch (System.ArgumentNullException) {
        System.Console.WriteLine(
            "The string is null.");
    }

    // Float to string conversion will not overflow.
    stringVal = System.Convert.ToString(floatVal);
    System.Console.WriteLine(
        "The float as a string is {0}.",
 stringVal);
}
public:
   void ConvertStringFloat( String^ stringVal )
   {
      float floatVal = 0;

      try
      {
         floatVal = System::Convert::ToSingle( stringVal );
         System::Console::WriteLine(
            "The String as a float is {0}.", floatVal
 );
      }
      catch ( System::OverflowException^ ) 
      {
         System::Console::WriteLine(
            "The conversion from String-to-float overflowed."
 );
      }
      catch ( System::FormatException^ ) 
      {
         System::Console::WriteLine(
            "The String is not formatted as a float."
 );
      }
      catch ( System::ArgumentNullException^ ) 
      {
         System::Console::WriteLine(
            "The String is 0." );
      }
      
      // Float to String conversion will not overflow.
      stringVal = System::Convert::ToString( floatVal );
      System::Console::WriteLine(
         "The float as a String is {0}.", stringVal
 );
   }
public void ConvertStringFloat(String stringVal)
{
    float floatVal = 0;

    try {        
        floatVal = System.Convert.ToSingle(stringVal);
        System.Console.WriteLine("The string as a float
 is {0}.", 
            System.Convert.ToString(floatVal));
    }
    catch (System.OverflowException exp) {        
        System.Console.WriteLine(
            "The conversion from string-to-float
 overflowed.");
    }
    catch (System.FormatException exp) {                    
        System.Console.WriteLine("The string is not formatted
 as a float.");
    }
    catch (System.ArgumentNullException exp){        
        System.Console.WriteLine("The string is null.");
    }

    // Float to string conversion will not overflow.
    stringVal = System.Convert.ToString(floatVal);
    System.Console.WriteLine("The float as a string
 is {0}.", stringVal);
} //ConvertStringFloat
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド

指定した値を、それと等価String 形式変換します
オーバーロードの一覧オーバーロードの一覧

名前 説明
Convert.ToString () 現在の Object を表す String返します
Convert.ToString (Boolean) 指定したブール値を、それと等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Byte) 指定した 8 ビット符号なし整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Char) 指定した Unicode 文字の値を、それと等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (DateTime) 指定した DateTime の値を、それと等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Decimal) 指定した Decimal数値を、それと等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Double) 指定した倍精度浮動小数点数値を、それと等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Int16) 指定した 16 ビット符号付き整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Int32) 指定した 32 ビット符号付き整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Int64) 指定した 64 ビット符号付き整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Object) 指定した Object の値を、その String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (SByte) 指定した 8 ビット符号付き整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Single) 指定した単精度浮動小数点数値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (String) 指定した Stringインスタンス返します実際変換処理は実行されません。
Convert.ToString (UInt16) 指定した 16 ビット符号なし整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (UInt32) 指定した 32 ビット符号なし整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (UInt64) 指定した 64 ビット符号なし整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Boolean, IFormatProvider) 指定したブール値を、それと等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Byte, IFormatProvider) 指定した 8 ビット符号なし整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Byte, Int32) 8 ビット符号なし整数値を、指定した基数表される等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Char, IFormatProvider) 指定した Unicode 文字の値を、それと等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (DateTime, IFormatProvider) 指定した DateTime の値を、それと等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Decimal, IFormatProvider) 指定した Decimal数値を、それと等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Double, IFormatProvider) 指定した倍精度浮動小数点数値を、それと等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Int16, IFormatProvider) 指定した 16 ビット符号付き整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Int16, Int32) 16 ビット符号付き整数の値を、指定した基数等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Int32, IFormatProvider) 指定した 32 ビット符号付き整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Int32, Int32) 32 ビット符号付き整数の値を、指定した基数等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Int64, IFormatProvider) 指定した 64 ビット符号付き整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Int64, Int32) 64 ビット符号付き整数の値を、指定した基数等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Object, IFormatProvider) 指定したカルチャに固有の書式情報使用して指定した Object の値を、それと等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (SByte, IFormatProvider) 指定した 8 ビット符号付き整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (Single, IFormatProvider) 指定した単精度浮動小数点数値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (String, IFormatProvider) 指定した Stringインスタンス返します実際変換処理は実行されません。
Convert.ToString (UInt16, IFormatProvider) 指定した 16 ビット符号なし整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (UInt32, IFormatProvider) 指定した 32 ビット符号なし整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

Convert.ToString (UInt64, IFormatProvider) 指定した 64 ビット符号なし整数の値を等価String 形式変換します

.NET Compact Framework によってサポートされています。

参照参照

Convert.ToString メソッド (Boolean)

指定したブール値を、それと等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

この実装は、Boolean.ToString と同じです。

使用例使用例

ToString使用してBooleanString変換する方法については、次のコード例参照してください

Public Sub ConvertStringBoolean(ByVal
 stringVal As String)

    Dim boolVal As Boolean
 = False

    Try
        boolVal = System.Convert.ToBoolean(stringVal)
        If boolVal Then
            System.Console.WriteLine( _
                "String is equal to System.Boolean.TrueString.")
        Else
            System.Console.WriteLine( _
                "String is equal to System.Boolean.FalseString.")
        End If
    Catch exception As System.FormatException
        System.Console.WriteLine( _
            "The string must equal System.Boolean.TrueString "
 + _
            "or System.Boolean.FalseString.")
    End Try

    ' A conversion from bool to string will always succeed.
    stringVal = System.Convert.ToString(boolVal)
    System.Console.WriteLine("{0} as a String is {1}",
 _
                              boolVal, stringVal)
End Sub
public void ConvertStringBoolean(string
 stringVal) {
    
    bool boolVal = false;

    try {
        boolVal = System.Convert.ToBoolean(stringVal);
        if (boolVal) {
            System.Console.WriteLine(
                "String was equal to System.Boolean.TrueString.");
        }
        else {
            System.Console.WriteLine(
                "String was equal to System.Boolean.FalseString.");
        }
    }
    catch (System.FormatException){
        System.Console.WriteLine(
            "The string must equal System.Boolean.TrueString
 " +
            "or System.Boolean.FalseString.");
    }

    // A conversion from bool to string will always succeed.
    stringVal = System.Convert.ToString(boolVal);
    System.Console.WriteLine("{0} as a string is {1}"
,
        boolVal, stringVal);
}
public:
   void ConvertStringBoolean( String^ stringVal )
   {
      bool boolVal = false;

      try
      {
         boolVal = System::Convert::ToBoolean( stringVal );
         if ( boolVal )
         {
            System::Console::WriteLine(
               "String was equal to System::Boolean::TrueString." );
         }
         else
         {
            System::Console::WriteLine(
               "String was equal to System::Boolean::FalseString." );
         }
      }
      catch ( System::FormatException^ ) 
      {
         System::Console::WriteLine( "The String must equal System::Boolean::TrueString
 " +
            "or System::Boolean::FalseString." );
      }
      
      // A conversion from bool to String will always succeed.
      stringVal = System::Convert::ToString( boolVal );
      System::Console::WriteLine( " {0} as a String is {1}",
         boolVal, stringVal );
   }
public void ConvertStringBoolean(String stringVal)
{
    boolean boolVal = false;

    try {        
        boolVal = System.Convert.ToBoolean(stringVal);
        if (boolVal) {            
            System.Console.WriteLine(
                "String was equal to System.Boolean.TrueString.");
        }
        else {            
            System.Console.WriteLine(
                "String was equal to System.Boolean.FalseString.");
        }
    }
    catch (System.FormatException exp) {        
        System.Console.WriteLine(
            ("The string must equal System.Boolean.TrueString
 "  
            + "or System.Boolean.FalseString."));
    }

    // A conversion from bool to string will always succeed.
    stringVal = System.Convert.ToString(boolVal);
    System.Console.WriteLine("{0} as a string is {1}"
, 
        System.Convert.ToString(boolVal), stringVal);
} //ConvertStringBoolean
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Char)

指定した Unicode 文字の値を、それと等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

この実装は、Char.ToString と同じです。

使用例使用例

ToString使用してCharString変換する方法については、次のコード例参照してください

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
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:
   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, 
            System.Convert.ToString(charVal));
    }
    catch (System.FormatException exp) {        
        System.Console.WriteLine("The string is longer than
 one character.");
    }
    catch (System.ArgumentNullException exp) {        
        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);
} //ConvertStringChar
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Int32)

指定した 32 ビット符号付き整数の値を等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

この実装は、Int32.ToString と同じです。

使用例使用例

既定書式設定使用してToString メソッド32 ビット整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (UInt16)

指定した 16 ビット符号なし整数の値を等価String 形式変換します

このメソッドは、CLS準拠していません。  

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
Public Shared Function ToString
 ( _
    value As UShort _
) As String
[CLSCompliantAttribute(false)] 
public static string ToString
 (
    ushort value
)
[CLSCompliantAttribute(false)] 
public:
static String^ ToString (
    unsigned short value
)
/** @attribute CLSCompliantAttribute(false) */ 
public static String ToString (
    UInt16 value
)
CLSCompliantAttribute(false) 
public static function ToString
 (
    value : ushort
) : String

パラメータ

value

16 ビット符号なし整数

戻り値
value の値と等価String

解説解説

この実装は、UInt16.ToString と同じです。

使用例使用例

既定書式設定使用してToString メソッド16 ビット符号なし整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (UInt64)

指定した 64 ビット符号なし整数の値を等価String 形式変換します

このメソッドは、CLS準拠していません。  

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
Public Shared Function ToString
 ( _
    value As ULong _
) As String
[CLSCompliantAttribute(false)] 
public static string ToString
 (
    ulong value
)
[CLSCompliantAttribute(false)] 
public:
static String^ ToString (
    usigned long long value
)
/** @attribute CLSCompliantAttribute(false) */ 
public static String ToString (
    UInt64 value
)
CLSCompliantAttribute(false) 
public static function ToString
 (
    value : ulong
) : String

パラメータ

value

64 ビット符号なし整数

戻り値
value の値と等価String

解説解説

この実装は、UInt64.ToString と同じです。

使用例使用例

既定書式設定使用してToString メソッド64 ビット符号なし整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Decimal)

指定した Decimal数値を、それと等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

この実装は、Decimal.ToString と同じです。

使用例使用例

ToString使用してDecimalString変換する方法については、次のコード例参照してください

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
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:
   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)
{
    System.Decimal decimalVal = System.Convert.ToDecimal(0);

    try {        
        decimalVal = System.Convert.ToDecimal(stringVal);
        System.Console.WriteLine("The string as a decimal
 is {0}.", 
            decimalVal);
    }
    catch (System.OverflowException exp) {
        System.Console.WriteLine(
            "The conversion from string to decimal overflowed.");
    }
    catch (System.FormatException exp) {        
        System.Console.WriteLine(
            "The string is not formatted as a decimal.");
    }
    catch (System.ArgumentNullException exp) {        
        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);
} //ConvertStringDecimal
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Int64, Int32)

64 ビット符号付き整数の値を、指定した基数等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Long, _
    toBase As Integer _
) As String
Dim value As Long
Dim toBase As Integer
Dim returnValue As String

returnValue = Convert.ToString(value, toBase)
public static string ToString
 (
    long value,
    int toBase
)
public:
static String^ ToString (
    long long value, 
    int toBase
)
public static String ToString (
    long value, 
    int toBase
)
public static function ToString
 (
    value : long, 
    toBase : int
) : String

パラメータ

value

64 ビット符号付き整数

toBase

戻り値基数。これは 2、8、10、または 16 である必要があります

戻り値
基数 toBase での valueString 形式

例外例外
例外種類条件

ArgumentException

toBase が 2、8、10、または 16 ではありません。

使用例使用例

ToString メソッド使用して、このメソッドサポートする基数に従って複数64 ビット整数String変換するコード例次に示します

' Example of the Convert.ToString( Long, Integer ) method.
Imports System
Imports Microsoft.VisualBasic

Module ConvertRadixLongDemo
    
    Sub RunToStringDemo( )

        Dim values as Long(
 ) = { _
            Long.MinValue, _
            -112233445566778899, _
            4294967296, _
            999999999999999999, _
            Long.MaxValue }
        Dim radices as Integer(
 ) = { 2, 8, 10, 16 }

        ' Iterate through the values array.
        Dim value as Long
        For Each value in
 values

            ' Iterate through the radices.
            Dim radix as Integer
            For Each radix in
 radices

                ' Convert a value with a radix.
                Dim valueString As String
 = _
                    Convert.ToString( value, radix )

                ' Display the results; use two lines, if necessary.
                If valueString.Length > 50 Then
                    Console.WriteLine( "{0,20} {1,3} "
 & _
                        vbCrLf & "          {2}",
 _
                        value, radix, valueString )
                Else
                    Console.WriteLine( "{0,20} {1,3}   {2}",
 _
                        value, radix, valueString )
                End If
            Next radix
        Next value
    End Sub 

    Sub Main()

        Console.WriteLine( _
            "This example of Convert.ToString( Long, Integer )
 " & _ 
            "generates " & vbCrLf & "the
 following output. It " & _
            "converts several Long values to " &
 vbCrLf & "strings " & _
            "using the radixes supported by the method."
 ) 
        Console.WriteLine( vbCrLf & _
            "          Value      Radix     String"
 & vbCrLf & _
            "          -----      -----     ------"
 )

        RunToStringDemo( )

    End Sub
End Module 

' This example of Convert.ToString( Long, Integer ) generates
' the following output. It converts several Long values to
' strings using the radixes supported by the method.
' 
'           Value      Radix     String
'           -----      -----     ------
' -9223372036854775808   2
'           1000000000000000000000000000000000000000000000000000000000000000
' -9223372036854775808   8   1000000000000000000000
' -9223372036854775808  10   -9223372036854775808
' -9223372036854775808  16   8000000000000000
'  -112233445566778899   2
'           1111111001110001010001000100011010100001000100101111000111101101
'  -112233445566778899   8   1771612104324104570755
'  -112233445566778899  10   -112233445566778899
'  -112233445566778899  16   fe714446a112f1ed
'           4294967296   2   100000000000000000000000000000000
'           4294967296   8   40000000000
'           4294967296  10   4294967296
'           4294967296  16   100000000
'   999999999999999999   2
'           110111100000101101101011001110100111011000111111111111111111
'   999999999999999999   8   67405553164730777777
'   999999999999999999  10   999999999999999999
'   999999999999999999  16   de0b6b3a763ffff
'  9223372036854775807   2
'           111111111111111111111111111111111111111111111111111111111111111
'  9223372036854775807   8   777777777777777777777
'  9223372036854775807  10   9223372036854775807
'  9223372036854775807  16   7fffffffffffffff
// Example of the Convert.ToString( long, int ) method.
using System;

class ConvertRadixLongDemo
{
    static void RunToStringDemo( )
    {
        long[ ] values = {
            long.MinValue,
            -112233445566778899, 
            4294967296, 
            999999999999999999, 
            long.MaxValue };
        int[ ]  radices = { 2, 8, 10, 16 };

        // Iterate through the values array.
        foreach( long value in values )
        {
            // Iterate through the radices.
            foreach( int radix in
 radices )
            {
                // Convert a value with a radix.
                string valueString = 
                    Convert.ToString( value, radix );

                // Display the results; use two lines, if necessary.
                if( valueString.Length > 50 )
                    Console.WriteLine( 
                        "{0,20} {1,3} \n          {2}", 
                        value, radix, valueString );
                else
                    Console.WriteLine( "{0,20} {1,3}   {2}", 
                        value, radix, valueString );
            }
        }
    } 

    static void Main( )
    {
        Console.WriteLine(
            "This example of Convert.ToString( long, int
 ) " +
            "generates \nthe following output. It converts several " +
            "long values to \nstrings using the radixes supported
 " +
            "by the method." );
        Console.WriteLine( 
            "\n          Value      Radix     String" +
            "\n          -----      -----     ------" );

        RunToStringDemo( );
    } 
} 

/*
This example of Convert.ToString( long, int ) generates
the following output. It converts several long values to
strings using the radixes supported by the method.

          Value      Radix     String
          -----      -----     ------
-9223372036854775808   2
          1000000000000000000000000000000000000000000000000000000000000000
-9223372036854775808   8   1000000000000000000000
-9223372036854775808  10   -9223372036854775808
-9223372036854775808  16   8000000000000000
 -112233445566778899   2
          1111111001110001010001000100011010100001000100101111000111101101
 -112233445566778899   8   1771612104324104570755
 -112233445566778899  10   -112233445566778899
 -112233445566778899  16   fe714446a112f1ed
          4294967296   2   100000000000000000000000000000000
          4294967296   8   40000000000
          4294967296  10   4294967296
          4294967296  16   100000000
  999999999999999999   2
          110111100000101101101011001110100111011000111111111111111111
  999999999999999999   8   67405553164730777777
  999999999999999999  10   999999999999999999
  999999999999999999  16   de0b6b3a763ffff
 9223372036854775807   2
          111111111111111111111111111111111111111111111111111111111111111
 9223372036854775807   8   777777777777777777777
 9223372036854775807  10   9223372036854775807
 9223372036854775807  16   7fffffffffffffff
*/
// Example of the Convert::ToString( Int64, Int32 ) method.
using namespace System;
using namespace System::Collections;
void RunToStringDemo()
{
   array<__int64>^values = {Int64::MinValue, -112233445566778899,4294967296
,999999999999999999,Int64::MaxValue};
   int radices[4] = {2,8,10,16};
   
   // Implement foreach( __int64 value in values ).
   IEnumerator^ myEnum = values->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      __int64 value = Convert::ToInt64( myEnum->Current );
      
      // Iterate through the radices.
      for ( int i = 0; i < 4; i++ )
      {
         
         // Convert a value with a radix.
         int radix = radices[ i ];
         String^ valueString = Convert::ToString( value, radix );
         
         // Display the results; use two lines, if necessary.
         if ( valueString->Length > 50 )
                  Console::WriteLine( "{0,20} {1,3} \n          {2}", value,
 radix, valueString );
         else
                  Console::WriteLine( "{0,20} {1,3}   {2}", value, radix,
 valueString );

      }
   }
}

int main()
{
   Console::WriteLine( "This example of Convert::ToString( __int64, int
 ) "
   "generates \nthe following output. It converts several "
   "__int64 values to \nstrings using the radixes supported
 "
   "by the method." );
   Console::WriteLine( "\n          Value      Radix     String"
   "\n          -----      -----     ------" );
   RunToStringDemo();
}

/*
This example of Convert::ToString( __int64, int ) generates
the following output. It converts several __int64 values to
strings using the radixes supported by the method.

          Value      Radix     String
          -----      -----     ------
-9223372036854775808   2
          1000000000000000000000000000000000000000000000000000000000000000
-9223372036854775808   8   1000000000000000000000
-9223372036854775808  10   -9223372036854775808
-9223372036854775808  16   8000000000000000
 -112233445566778899   2
          1111111001110001010001000100011010100001000100101111000111101101
 -112233445566778899   8   1771612104324104570755
 -112233445566778899  10   -112233445566778899
 -112233445566778899  16   fe714446a112f1ed
          4294967296   2   100000000000000000000000000000000
          4294967296   8   40000000000
          4294967296  10   4294967296
          4294967296  16   100000000
  999999999999999999   2
          110111100000101101101011001110100111011000111111111111111111
  999999999999999999   8   67405553164730777777
  999999999999999999  10   999999999999999999
  999999999999999999  16   de0b6b3a763ffff
 9223372036854775807   2
          111111111111111111111111111111111111111111111111111111111111111
 9223372036854775807   8   777777777777777777777
 9223372036854775807  10   9223372036854775807
 9223372036854775807  16   7fffffffffffffff
*/
// Example of the Convert.ToString( long, int ) method.
import System.* ;

class ConvertRadixLongDemo
{   
    static void RunToStringDemo()
    {
        long values[] = { Long.MIN_VALUE, -112233445566778899L, 4294967296L,
                        999999999999999999L, Long.MAX_VALUE    };
        int radices[] =  { 2, 8, 10, 16 };

        // Iterate through the values array.
        for (int iCtr = 0; iCtr < values.length;
 iCtr++)    {
            long value = values[iCtr];

            // Iterate through the radices
            for (int iCtr1 = 0; iCtr1 <
 radices.length; iCtr1++)
            {
                int radix = radices[iCtr1];

                // Iterate through the radices.
                // Convert a value with a radix.
                String valueString = Convert.ToString(value, radix);

                // Display the results; use two lines, if necessary.
                if (valueString.get_Length() > 50) {
                    Console.WriteLine("{0,20} {1,3} \n          {2}", 
                        System.Convert.ToString(value), 
                        System.Convert.ToString(radix), valueString);
                }
                else {
                    Console.WriteLine("{0,20} {1,3}   {2}", 
                        System.Convert.ToString(value), 
                        System.Convert.ToString(radix), valueString);
                }
            }
        }
    } //RunToStringDemo   

    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of Convert.ToString( long, int
 ) " 
            + "generates \nthe following output. It converts several "
 
            + "long values to \nstrings using the radixes
 supported " 
            + "by the method."));
        Console.WriteLine(("\n          Value      Radix     String" 
            + "\n          -----      -----     ------"));

        RunToStringDemo();
    } //main
} //ConvertRadixLongDemo

/*
This example of Convert.ToString( long, int ) generates
the following output. It converts several long values to
strings using the radixes supported by the method.

          Value      Radix     String
          -----      -----     ------
-9223372036854775808   2
          1000000000000000000000000000000000000000000000000000000000000000
-9223372036854775808   8   1000000000000000000000
-9223372036854775808  10   -9223372036854775808
-9223372036854775808  16   8000000000000000
 -112233445566778899   2
          1111111001110001010001000100011010100001000100101111000111101101
 -112233445566778899   8   1771612104324104570755
 -112233445566778899  10   -112233445566778899
 -112233445566778899  16   fe714446a112f1ed
          4294967296   2   100000000000000000000000000000000
          4294967296   8   40000000000
          4294967296  10   4294967296
          4294967296  16   100000000
  999999999999999999   2
          110111100000101101101011001110100111011000111111111111111111
  999999999999999999   8   67405553164730777777
  999999999999999999  10   999999999999999999
  999999999999999999  16   de0b6b3a763ffff
 9223372036854775807   2
          111111111111111111111111111111111111111111111111111111111111111
 9223372036854775807   8   777777777777777777777
 9223372036854775807  10   9223372036854775807
 9223372036854775807  16   7fffffffffffffff
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (UInt64, IFormatProvider)

指定した 64 ビット符号なし整数の値を等価String 形式変換します

このメソッドは、CLS準拠していません。  

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
Public Shared Function ToString
 ( _
    value As ULong, _
    provider As IFormatProvider _
) As String
Dim value As ULong
Dim provider As IFormatProvider
Dim returnValue As String

returnValue = Convert.ToString(value, provider)
[CLSCompliantAttribute(false)] 
public static string ToString
 (
    ulong value,
    IFormatProvider provider
)
[CLSCompliantAttribute(false)] 
public:
static String^ ToString (
    usigned long long value, 
    IFormatProvider^ provider
)
/** @attribute CLSCompliantAttribute(false) */ 
public static String ToString (
    UInt64 value, 
    IFormatProvider provider
)
CLSCompliantAttribute(false) 
public static function ToString
 (
    value : ulong, 
    provider : IFormatProvider
) : String

パラメータ

value

64 ビット符号なし整数

provider

カルチャに固有の書式情報提供する IFormatProvider インターフェイス実装

戻り値
value の値と等価String

解説解説

この実装は、UInt64.ToString と同じです。

使用例使用例

IFormatProvider オブジェクト使用してToString メソッド64 ビット符号なし整数String変換するコード例次に示します

' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo
 = new NumberFormatInfo( )
        Dim formatter   As String
           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer(
 ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte
     = 140
        Dim SByteA      As SByte    = Convert.ToSByte(
 -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16(
 61680 )
        Dim Int16A      As Short
    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32(
 4042322160 )
        Dim Int32A      As Integer
  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long
     = -1085102592571150095

        Dim SingleA     As Single
   = -32.375F
        Dim DoubleA     As Double
   = 61680.3855
        Dim DecimA      As Decimal
  = 4042322160.252645135D
        Dim ObjDouble   As Object
   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " &
 _
            "Convert.ToString( numeric types ) and "
 & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider
 ) " & _
            vbCrLf & "converts values of each of the CLR base
 " & _
            "numeric types to strings, " & vbCrLf
 & "using " & _
            "default formatting and a NumberFormatInfo object."
 )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties
 " & _
            "that are changed, " & vbCrLf &
 "only the negative " & _
            "sign and decimal separator affect the conversions."
 )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format
 Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------"
 )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed
,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[
 ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric
 types " +
            "to strings, \nusing default formatting and a
 " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider"
 );
        Console.WriteLine( formatter, "-------", "---------------"
 );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
using namespace System;
using namespace System::Globalization;
int main()
{
   // Create a NumberFormatInfo object and set several of its
   // properties that apply to numbers.
   NumberFormatInfo^ provider = gcnew NumberFormatInfo;
   String^ formatter = "{0,22}   {1}";

   // These properties will affect the conversion.
   provider->NegativeSign = "minus ";
   provider->NumberDecimalSeparator = " point ";

   // These properties will not be applied.
   provider->NumberDecimalDigits = 2;
   provider->NumberGroupSeparator = ".";
   array<Int32>^sizes = {3};
   provider->NumberGroupSizes = sizes;

   // Convert these values using default values and the
   // format provider created above.
   Byte ByteA = 140;
   SByte SByteA = -60;
   UInt16 UInt16A = 61680;
   short Int16A = -3855;
   UInt32 UInt32A = 4042322160;
   int Int32A = -252645135;
   UInt64 UInt64A = 8138269444283625712;
   __int64 Int64A = -1085102592571150095;
   float SingleA = -32.375F;
   double DoubleA = 61680.3855;
   Decimal DecimA = Convert::ToDecimal( "4042322160.252645135" );
   Object^ ObjDouble =  -98765.4321;
   Console::WriteLine( "This example of "
   "Convert::ToString( numeric types ) and \n"
   "Convert::ToString( numeric types, IFormatProvider* ) \n"
   "converts values of each of the CLR base numeric types
 "
   "to strings, \nusing default formatting and a "
   "NumberFormatInfo object." );
   Console::WriteLine( "\nNote: Of the several NumberFormatInfo "
   "properties that are changed, \nonly the negative sign "
   "and decimal separator affect the conversions.\n" );
   Console::WriteLine( formatter, "Default", "Format Provider"
 );
   Console::WriteLine( formatter, "-------", "---------------"
 );

   // Convert the values with and without a format provider.
   Console::WriteLine( formatter, Convert::ToString( ByteA ), Convert::ToString(
 ByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SByteA ), Convert::ToString(
 SByteA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt16A ), Convert::ToString(
 UInt16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int16A ), Convert::ToString(
 Int16A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt32A ), Convert::ToString(
 UInt32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int32A ), Convert::ToString(
 Int32A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( UInt64A ), Convert::ToString(
 UInt64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( Int64A ), Convert::ToString(
 Int64A, provider ) );
   Console::WriteLine( formatter, Convert::ToString( SingleA ), Convert::ToString(
 SingleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DoubleA ), Convert::ToString(
 DoubleA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( DecimA ), Convert::ToString(
 DecimA, provider ) );
   Console::WriteLine( formatter, Convert::ToString( ObjDouble ), Convert::ToString(
 ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
import System.* ;
import System.Globalization.* ;

class ConvertNumericProviderDemo
{   
    public static void main(String[]
 args)
    {    
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider =  new NumberFormatInfo();
        String formatter = "{0,22}   {1}";
      
        // These properties will affect the conversion.
        provider.set_NegativeSign("minus ");
        provider.set_NumberDecimalSeparator(" point ");
      
        // These properties will not be applied.
        provider.set_NumberDecimalDigits(2);
        provider.set_NumberGroupSeparator(".");
        provider.set_NumberGroupSizes(new int[]{3});
      
        // Convert these values using default values and the
        // format provider created above.
        ubyte byteA = 140;
        SByte sByteA = (SByte)(-60);
        UInt16 uInt16A = (UInt16)61680;
        short int16A = -3855;
      
        UInt32 uInt32A = (UInt32)(4042322160L);
        int int32A = -252645135;
        UInt64  uInt64A     =(UInt64)8138269444283625712L;
        long    int64A      = -1085102592571150095L;
      
        float singleA = (float)-32.375;
        double doubleA = 61680.3855;
        System.Decimal decimA = System.Convert.ToDecimal(4042322160.252645135);
        Object objDouble = (System.Double)(-98765.4321);
      
        Console.WriteLine(("This example of " 
            + "Convert.ToString( numeric types ) and \n"
            + "Convert.ToString( numeric types, IFormatProvider ) \n" 
            + "converts values of each of the CLR base numeric
 types " 
            + "to strings, \nusing default formatting and
 a " 
            + "NumberFormatInfo object."));
        Console.WriteLine(("\nNote: Of the several NumberFormatInfo "
            + "properties that are changed, \nonly the negative sign "
 
            + "and decimal separator affect the conversions.\n"));
        Console.WriteLine(formatter, "Default", "Format Provider");
        Console.WriteLine(formatter, "-------", "---------------");
      
        // Convert the values with and without a format provider.
        Console.WriteLine(formatter, Convert.ToString(byteA), 
            Convert.ToString(byteA, provider));
        Console.WriteLine(formatter, Convert.ToString(sByteA), 
            Convert.ToString(sByteA, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt16A), 
            Convert.ToString(uInt16A, provider));
        Console.WriteLine(formatter, Convert.ToString(int16A), 
            Convert.ToString(int16A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(uInt32A), 
            Convert.ToString(uInt32A, provider));
        Console.WriteLine(formatter, Convert.ToString(int32A), 
            Convert.ToString(int32A, provider));
        Console.WriteLine(formatter, Convert.ToString(uInt64A), 
            Convert.ToString(uInt64A, provider));
        Console.WriteLine(formatter, Convert.ToString(int64A), 
            Convert.ToString(int64A, provider));
      
        Console.WriteLine(formatter, Convert.ToString(singleA), 
            Convert.ToString(singleA, provider));
        Console.WriteLine(formatter, Convert.ToString(doubleA), 
            Convert.ToString(doubleA, provider));
        Console.WriteLine(formatter, Convert.ToString(decimA), 
            Convert.ToString(decimA, provider));
        Console.WriteLine(formatter, Convert.ToString(objDouble), 
            Convert.ToString(objDouble, provider));
    } //main
} //ConvertNumericProviderDemo

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings
,
using default formatting and a NumberFormatInfo
 object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Convert.ToString メソッド (Byte, Int32)

8 ビット符号なし整数値を、指定した基数表される等価String 形式変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToString
 ( _
    value As Byte, _
    toBase As Integer _
) As String
Dim value As Byte
Dim toBase As Integer
Dim returnValue As String

returnValue = Convert.ToString(value, toBase)
public static string ToString
 (
    byte value,
    int toBase
)
public:
static String^ ToString (
    unsigned char value, 
    int toBase
)
public static String ToString (
    byte value, 
    int toBase
)
public static function ToString
 (
    value : byte, 
    toBase : int
) : String

パラメータ

value

8 ビット符号なし整数

toBase

戻り値基数。これは 2、8、10、または 16 である必要があります

戻り値
基数 toBase での valueString 形式

例外例外
例外種類条件

ArgumentException

toBase が 2、8、10、または 16 ではありません。

使用例使用例

ToString メソッド使用し、このメソッドサポートする基数に従って複数Byte の値を String変換するコード例次に示します

' Example of the Convert.ToString( Byte, Integer ) method.
Imports System
Imports Microsoft.VisualBasic

Module ConvertRadixByteDemo
    
    Sub RunToStringDemo( )

        Dim values as Byte(
 ) = { _
            Byte.MinValue, _
            13, _
            Byte.MaxValue }
        Dim radices as Integer(
 ) = { 2, 8, 10, 16 }

        ' Iterate through the values array.
        Dim value as Byte
        For Each value in
 values

            ' Iterate through the radices.
            Dim radix as Integer
            For Each radix in
 radices

                ' Convert a value with a radix.
                Dim valueString As String
 = _
                    Convert.ToString( value, radix )

                Console.WriteLine( "{0,7}  {1,3}    {2}",
 _
                    value, radix, valueString )
            Next radix
        Next value
    End Sub 

    Sub Main( )

        Console.WriteLine( _
            "This example of Convert.ToString( Byte, Integer )
 " & _ 
            "generates " & vbCrLf & "the
 following output. It " & _
            "converts several Byte values to " &
 vbCrLf & "strings " & _
            "using the radixes supported by the method."
 ) 
        Console.WriteLine( vbCrLf & _
            "  Value  Radix  String" & vbCrLf
 & _
            "  -----  -----  ------" )

        RunToStringDemo( )

    End Sub
End Module 

' This example of Convert.ToString( Byte, Integer ) generates
' the following output. It converts several Byte values to
' strings using the radixes supported by the method.
' 
'   Value  Radix  String
'   -----  -----  ------
'       0    2    0
'       0    8    0
'       0   10    0
'       0   16    0
'      13    2    1101
'      13    8    15
'      13   10    13
'      13   16    d
'     255    2    11111111
'     255    8    377
'     255   10    255
'     255   16    ff
// Example of the Convert.ToString( byte, int ) method.
using System;

class ConvertRadixByteDemo
{
    static void RunToStringDemo( )
    {
        byte[ ] values = {
            byte.MinValue, 
            13, 
            byte.MaxValue };
        int[ ]  radices = { 2, 8, 10, 16 };

        // Iterate through the values array.
        foreach( byte value in values )
        {
            // Iterate through the radices.
            foreach( int radix in
 radices )
            {
                // Convert a value with a radix.
                string valueString = 
                    Convert.ToString( value, radix );

                Console.WriteLine( "{0,7}  {1,3}    {2}", 
                    value, radix, valueString );
            }
        }
    } 

    static void Main( )
    {
        Console.WriteLine(
            "This example of Convert.ToString( byte, int
 ) " +
            "generates \nthe following output. It converts several " +
            "byte values to \nstrings using the radixes supported
 " +
            "by the method." );
        Console.WriteLine( 
            "\n  Value  Radix  String" +
            "\n  -----  -----  ------" );

        RunToStringDemo( );
    } 
} 

/*
This example of Convert.ToString( byte, int ) generates
the following output. It converts several byte values to
strings using the radixes supported by the method.

  Value  Radix  String
  -----  -----  ------
      0    2    0
      0    8    0
      0   10    0
      0   16    0
     13    2    1101
     13    8    15
     13   10    13
     13   16    d
    255    2    11111111
    255    8    377
    255   10    255
    255   16    ff
*/
// Example of the Convert::ToString( unsigned char, int ) method.
using namespace System;
using namespace System::Collections;
void RunToStringDemo()
{
   array<unsigned char>^values = {Byte::MinValue,13,Byte::MaxValue};
   int radices[4] = {2,8,10,16};
   
   // Implement foreach( unsigned char value in values ).
   IEnumerator^ myEnum = values->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      unsigned char value = Convert::ToByte( myEnum->Current
 );
      
      // Iterate through the radices.
      for ( int i = 0; i < 4; i++ )
      {
         
         // Convert a value with a radix.
         int radix = radices[ i ];
         String^ valueString = Convert::ToString( value, radix );
         Console::WriteLine( "{0,7}  {1,3}    {2}", value, radix, valueString
 );

      }
   }
}

int main()
{
   Console::WriteLine( "This example of Convert::ToString( unsigned char,
 int ) "
   "generates \nthe following output. It converts several "
   "unsigned char values to \nstrings using
 the radixes "
   "supported by the method." );
   Console::WriteLine( "\n  Value  Radix  String"
   "\n  -----  -----  ------" );
   RunToStringDemo();
}

/*
This example of Convert::ToString( unsigned char, int
 ) generates
the following output. It converts several unsigned char values
 to
strings using the radixes supported by the method.

  Value  Radix  String
  -----  -----  ------
      0    2    0
      0    8    0
      0   10    0
      0   16    0
     13    2    1101
     13    8    15
     13   10    13
     13   16    d
    255    2    11111111
    255    8    377
    255   10    255
    255   16    ff
*/
// Example of the Convert.ToString( byte, int ) method.
import System.* ;

class ConvertRadixByteDemo
{
    static void RunToStringDemo() 
    {
        ubyte values[] =  { 0, 13, 255 };
        int radices[] =  { 2, 8, 10, 16 };       
           
        // Iterate through the values array.
        for(int iCtr = 0 ; iCtr < values.length
 ; iCtr++) {

            ubyte value = (values[iCtr]);
            // Iterate through the radices.
            for(int iCtr1 = 0 ; iCtr1 <
 radices.length ; iCtr1++) {
                int radix= radices[iCtr1];
         
                // Convert a value with a radix.
                String valueString = Convert.ToString(value, radix);
                Console.WriteLine("{0,7}  {1,3}    {2}",
                    System.Convert.ToString(value),
                    System.Convert.ToString(radix), valueString);
            }
        }
    } //RunToStringDemo   
   
    public static void main(String[]
 args)
    {   
        Console.WriteLine(("This example of Convert.ToString( byte, int
 ) " 
            + "generates \nthe following output. It converts several "
 
            + "byte values to \nstrings using the radixes
 supported " 
            + "by the method."));
        Console.WriteLine(("\n  Value  Radix  String"
            + "\n  -----  -----  ------"));
      
        RunToStringDemo();
    } //main
} //ConvertRadixByteDemo

/*
This example of Convert.ToString( byte, int ) generates
the following output. It converts several byte values to
strings using the radixes supported by the method.

  Value  Radix  String
  -----  -----  ------
      0    2    0
      0    8    0
      0   10    0
      0   16    0
     13    2    1101
     13    8    15
     13   10    13
     13   16    d
    255    2    11111111
    255    8    377
    255   10    255
    255   16    ff
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からConvert.ToString メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からConvert.ToString メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からConvert.ToString メソッドを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Convert.ToString メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS