Convert.ToString( non-numeric types, IFormatProvider ). : Data Type Convert « Data Type « VB.Net Tutorial






Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Public Class DummyProvider
    Implements IFormatProvider

    Public Function GetFormat( argType As Type ) As Object _
        Implements IFormatProvider.GetFormat
        Console.Write( "{0,-40}", argType.ToString( ) )
        Return Nothing
    End Function 
End Class

Module MainClass
    Sub Main( )
        Dim provider    As New DummyProvider( )
        Dim converted   As String

        Dim Int32A      As Integer  = -1111111   
        Dim DoubleA     As Double   = 6.3
        Dim ObjDouble   As Object   = CType( -98765.4321, Object )
        Dim DayTimeA    As DateTime = new DateTime( 2010, 9, 1, 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 )

        converted =  Convert.ToString( Int32A, provider )
        Console.WriteLine( "Int32    {0}", converted )

        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 )

        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








2.45.Data Type Convert
2.45.1.CLng: convert integer to long
2.45.2.CByte: convert to byte
2.45.3.CSng: convert to Single
2.45.4.CDbl: convert to double
2.45.5.CDec: convert to decimal
2.45.6.Call Int64TryParse(String, NumberStyles, IFormatProvider, Int32)
2.45.7.Convert a string into a 64-bit signed integer value using the Int64.Parse(String) method
2.45.8.Convert.ToBase64CharArray() and Convert.FromBase64CharArray methods
2.45.9.Converts the bit patterns of UInt32 values to Byte arrays with the GetBytes method.
2.45.10.Convert.ToString( non-numeric types, IFormatProvider ).
2.45.11.Create a hexadecimal value out of range of the UInt64 type and Convert it back to a number.