那麼,我有這段代碼。我想將文本框的內容存儲到一個字符串數組中(我首選使用字符串列表),然後將數組的每個元素打印到另一個文本框中。然而,當我嘗試編譯此代碼我收到此錯誤信息: System.InvalidCastException:「從字符串轉換‘’爲int無效」 出現FormatException:輸入字符串是不是正確的格式如何解決vb.net中的system.invalidcastexception
有什麼建議?
Public Class NewUser
Dim textUser As String
Dim strUserName As New List(Of String)
Private Sub btnCreateUser_Click(sender As Object, e As EventArgs) Handles btnCreateUser.Click
textUser = txtNewUser.Text
If textUser <> "" Then
strUserName.Add(textUser)
txtNewUser.Clear()
Else
MsgBox("Username or Password is missing. Try again!")
End If
For Each i As String In strUserName
TextBox1.Text = String.Join(",", strUserName(i))
Next i
End Sub
End Class
哪一行會拋出異常? – David
@David TextBox1.Text = String.Join(「,」,strUserName(i)) –