ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

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

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

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.