Home >>VB.Net Programs >VB.Net program to convert different types of variables into the string

VB.Net program to convert different types of variables into the string

Convert different types of variables into string in VB.Net program

Using the ToString() method, we can create a program for converting various types of variables into a string.

Program

Below is the source code for converting different types of variables into a string. The program given is compiled and successfully executed.


Module Module1
    Sub Main()
        Dim w As Double = 987654.321
        Dim x As Integer = 987
        Dim y As Byte = 987
        Dim z As Boolean = False

        Dim str As String

        str = w.ToString()
        Console.WriteLine(str)

        str = x.ToString()
        Console.WriteLine(str)

        str = y.ToString()
        Console.WriteLine(str)

        str = z.ToString()
        Console.WriteLine(str)

        Console.ReadLine()
    End Sub
End Module
	
Output:
987654.321
987
987
False

Explanation:

We created a Module in the above program containing the Main() process, here we created four local variables w, x, y and z, respectively initialized 987654.321, 987, 987, and False.

str = w.ToString()
Console.WriteLine(str)

str = x.ToString()
Console.WriteLine(str)

str = y.ToString()
Console.WriteLine(str)

str = z.ToString()
Console.WriteLine(str)

Here using the ToString() method, we converted the various types of data types into a string and then printed the values of the variables on the console screen.


No Sidebar ads