「VB.NET」Parseメソッドで文字列を数値に変換する

書式
Integer.Parse(数値)
Long.Parse(数値)
使用例

Module Module1

    Sub Main()
        Dim num As String = "345.678"

        '関数funcAを呼び出す
        funcA(num)

        Console.ReadKey()

    End Sub

    Sub funcA(ByVal nn As Integer)


        Dim res As Integer = Integer.Parse(nn)
        Console.WriteLine("文字列をInteger型に変換")
        Console.WriteLine(res)


        Dim resB As Long = Long.Parse(nn)
        Console.WriteLine("文字列をLong型に変換")
        Console.WriteLine(resB)


        Dim resD As Double = Double.Parse(nn)
        Console.WriteLine("文字列をDouble型に変換")
        Console.WriteLine(resD)


        Dim resC As Single = Single.Parse(nn)
        Console.WriteLine("文字列をSingle型に変換")
        Console.WriteLine(resC)

    End Sub

End Module

結果
文字列をInteger型に変換
346
文字列をLong型に変換
346
文字列をDouble型に変換
346
文字列をSingle型に変換
346

VB.net

Posted by arkgame