我在 Visual Studio 2015 Visual Basic(我认为这就是 VB.net)中并收到此错误:
BC30311“Uri()”类型的值无法转换为“List(Of Uri)”
在此代码的第 2 行:
Public Class Form1
Public Pages As List(Of Uri) = {New Uri("https://google.com/")}
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Searchbar.Text.Contains("http://") Or Searchbar.Text.Contains("https://") Then
WebBrowser1.Url = New Uri(Searchbar.Text)
Pages.Add(New Uri(Searchbar.Text))
Else
If Not Searchbar.Text.Equals("") Then
WebBrowser1.Url = New Uri("http://" & Searchbar.Text)
Pages.Add(New Uri("http://" & Searchbar.Text))
' Pages.Add(New Uri("http://" & Searchbar.Text))
End If
End If
End Sub
End Class
我在互联网上没有找到任何似乎与此特定错误有关的内容,而且我不明白我所做的与此页面上的内容有什么不同。我做错了什么?
编辑:谢谢,现在可以了!
您初始化列表的代码是错误的。请参阅下面的代码。
Public Pages As List(Of Uri) = New List(Of Uri)(New Uri() {
New Uri("https://google.com/"),
New Uri("https://amazon.com/")
})
替代代码。
Public Pages As List(Of Uri) = New List(Of Uri) From {
New Uri("https://google.com/"),
New Uri("https://amazon.com/")
}
正如Han所说,初始化不正确。这是另一种选择
Public Pages As List(Of Uri) = {New Uri("https://google.com/"),
New Uri("http://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET/"),
New Uri("https://amazon.com/")}.ToList