在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方法的基本用法,根據不同的數據類型和需求可以進行適當的調整和擴展。