VB.Net by API/System/Convert — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:40, 26 мая 2010

Convert.FromBase64String

  
Public Class Tester
    Public Shared Sub Main
        Dim quote As String = "AAAAA"
        Dim quoteBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(quote)
        Dim quote64 As String = Convert.ToBase64String(quoteBytes)
        Dim byteSet As Byte() = Convert.FromBase64String(quote64)
        
        Dim result As String = System.Text.Encoding.UTF8.GetString(byteSet)
        
        Console.WriteLine(quote & vbNewLine & quote64 & vbNewLine & result)
    End Sub
End Class


Convert.ToBase64String

  
Public Class Tester
    Public Shared Sub Main
        Dim quote As String = "AAAAA"
        Dim quoteBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(quote)
        Dim quote64 As String = Convert.ToBase64String(quoteBytes)
        Dim byteSet As Byte() = Convert.FromBase64String(quote64)
        
        Dim result As String = System.Text.Encoding.UTF8.GetString(byteSet)
        
        Console.WriteLine(quote & vbNewLine & quote64 & vbNewLine & result)
    End Sub
End Class


Convert.ToInt32

  
Imports System
Imports System.Text
Imports System.Text.RegularExpressions

Public Class MainClass
    Shared Sub Main(  )
        Dim blnTrue As Boolean = True
        Dim blnOne As Boolean = 1
        Dim blnNegOne As Boolean = -1
        Dim blnFalse As Boolean = False
    
        If Convert.ToInt16(blnNegOne) = 1 Then
          Console.WriteLine(blnFalse)
          Console.WriteLine(Convert.ToString(Convert.ToInt32(blnFalse)))
        End If
    End Sub "Main
   
End Class


Convert.ToInt64

  
Imports System

Public Class MainClass
    Shared Sub Main(  )
        Dim l As Long
        Dim s As Single
    
        l = Long.MaxValue
        Console.WriteLine(l)
    
        s = Convert.ToSingle(l)
        s -= 1000000000000
        l = Convert.ToInt64(s)
    
        Console.WriteLine(l)
    End Sub "Main
   
End Class


Convert.ToSingle

  
Imports System

Public Class MainClass
    Shared Sub Main(  )
        Dim l As Long
        Dim s As Single
    
        l = Long.MaxValue
        Console.WriteLine(l)
    
        s = Convert.ToSingle(l)
        s -= 1000000000000
        l = Convert.ToInt64(s)
    
        Console.WriteLine(l)
    End Sub "Main
   
End Class


Convert.ToUInt16

  
Imports System
Imports System.Text
Imports System.Text.RegularExpressions

Public Class MainClass
    Shared Sub Main(  )
        Dim shrShort As Short
        Dim shrUInt16 As UInt16
        Dim shrInt16 As Int16
        Dim intInteger As Integer
        Dim intUInt32 As UInt32
        Dim intInt32 As Int32
        Dim lngLong As Long
        Dim lngInt64 As Int64
    
        shrShort = 0
        shrUInt16 = Convert.ToUInt16(shrShort)
        shrInt16 = shrShort
        intInteger = shrShort
        intUInt32 = Convert.ToUInt32(shrShort)
        intInt32 = shrShort
        lngInt64 = shrShort
    
        lngLong = lngLong.MaxValue
        If lngLong > Short.MaxValue Then
          shrShort = Convert.ToInt16(lngLong)
        End If
        intInteger = CInt(lngLong)
    
    End Sub "Main
   
End Class