VB.Net Tutorial/Data Type/Data Type Convert
Содержание
CByte: convert to byte
<source lang="vbnet">Module Tester
Public Sub Main() Dim iInteger As Integer = 5280 Dim lLong As Long Dim bytByte As Byte Dim sngSingle As Single Dim dblDouble As Double Dim decDecimal As Decimal Console.Writeline("Convert to a Byte: {0}", CByte(iInteger)) End Sub
End Module</source>
Unhandled Exception: System.OverflowException: Arithmetic operation resulted in an overflow. at Tester.Main()
CDbl: convert to double
<source lang="vbnet">Module Tester
Public Sub Main() Dim iInteger As Integer = 5280 Dim lLong As Long Dim bytByte As Byte Dim sngSingle As Single Dim dblDouble As Double Dim decDecimal As Decimal Console.WriteLine("Convert to a Double: {0}", CDbl(iInteger) / 6.123) End Sub
End Module</source>
Convert to a Double: 862.322390984811
CDec: convert to decimal
<source lang="vbnet">Module Tester
Public Sub Main() Dim iInteger As Integer = 5280 Dim lLong As Long Dim bytByte As Byte Dim sngSingle As Single Dim dblDouble As Double Dim decDecimal As Decimal Console.WriteLine("Convert to a Decimal: {0}", CDec(iInteger) / 34) End Sub
End Module</source>
Convert to a Decimal: 155.29411764705882352941176471
CLng: convert integer to long
<source lang="vbnet">Module Tester
Public Sub Main() Dim iInteger As Integer = 5280 Dim lLong As Long Dim bytByte As Byte Dim sngSingle As Single Dim dblDouble As Double Dim decDecimal As Decimal Console.WriteLine("Convert to a Long: {0}", CLng(iInteger) * CLng(iInteger)) End Sub
End Module</source>
Convert to a Long: 27878400
CSng: convert to Single
<source lang="vbnet">Module Tester
Public Sub Main() Dim iInteger As Integer = 5280 Dim lLong As Long Dim bytByte As Byte Dim sngSingle As Single Dim dblDouble As Double Dim decDecimal As Decimal Console.WriteLine("Convert to a Single: {0}", CSng(iInteger) / 3.4) End Sub
End Module</source>
Convert to a Single: 1552.94117647059