在VB中,ToString方法用于將對(duì)象轉(zhuǎn)換為其等效的字符串表示形式。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方法的基本用法,根據(jù)不同的數(shù)據(jù)類型和需求可以進(jìn)行適當(dāng)?shù)恼{(diào)整和擴(kuò)展。