在VB中,ToString方法用于将对象转换为其等效的字符串表示形式。ToString方法的使用方法有以下几种:
Dim num As Integer = 10
Dim str As String = num.ToString()
Class Person
Public Name As String
Public Age As Integer
Public Overrides Function ToString() As String
Return "Name: " & Name & ", Age: " & Age.ToString()
End Function
End Class
Dim p As New Person()
p.Name = "John"
p.Age = 25
Dim str As String = p.ToString()
Dim arr As Integer() = {1, 2, 3, 4, 5}
Dim str As String = String.Join(", ", arr)
str = str.ToString()
以上是ToString方法的基本用法,根据不同的数据类型和需求可以进行适当的调整和扩展。