×

VB.Net Programs

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

By Nidhi Last Updated : October 13, 2024

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.