CStr Function in VB.NET

How to use CStr Function?

Explanation

CStr Function

CStr Function in Visual Basic.net 2008 is used to convert an expression to String Datatype. This function uses the locale settings of the system to convert to string datatype.
Syntax:

CStr(expression)
Example:

Module Module1
Sub Main()
Dim x As Double = 254.67
Dim text As String = 2
Dim a As String
a = "2" + CStr(x)
Console.WriteLine("The Concatenated result of two
strings is::" & a)
Console.ReadLine()
End Sub
End Module
Result:

The Concatenated result of two strings is ::2254.67

In the above CStr Function example, an integer is converted to string and concatenated with a string '2' to get the result as 2254.67.

Visual Basic Tutorial


Ask Questions

Ask Question