Example. This program calls the CStr function and passes 5 as the argument. It shows that you can convert the Boolean True into the String "True" by using the CStr function.
Finally It converts the Char (a) into the String "a". It uses the CStr function for this as well.
' Convert integer to string.
Dim str As String = CStr(5)
If str = "5" Then
' Convert bool to string.
str = CStr(True)
If str = "True" Then
' Convert char to string.
str = CStr("a"c)
If str = "a" Then
Internals. How does the .NET Framework implement the CStr function? It is compiled CStr into the Conversions.ToString function. This eventually returns the correct String value.
Note The CStr("a"c) call above is optimized out by the Visual Basic .NET compiler for better performance.
Summary. The CStr function provides a way to effectively convert value types into String types. It is useful—you cannot call ToString on literals in the VB.NET environment.