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

Here, we are going to learn how to convert different types of variables into the string in VB.Net?
Submitted by Nidhi, on November 26, 2020 [Last updated : February 18, 2023]

Converting different types of variables into the string

We will create a program to convert different types of variables into the string using the ToString() method.

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

The source code to convert different types of variables into the string is given below. The given program is compiled and executed successfully.

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

Module Module1
    Sub Main()
        Dim a As Double = 123456.789
        Dim b As Integer = 123
        Dim c As Byte = 123
        Dim d As Boolean = False

        Dim str As String

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

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

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

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

        Console.ReadLine()
    End Sub

End Module

Output:

123456.789
123
123
False

Explanation:

In the above program, we created a Module that contains the Main() method, here we created four local variables a, b, c, and d that are initialized 123456.789, 123, 123, and False respectively.

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

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

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

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

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

VB.Net String Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.