我是VB.NET的新手,我试图弄清楚为什么它会在下面的代码的第一部分出现System.string [],并且在第二部分我想知道为什么价值即将到来4x4次
这是我的代码
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Colours() As String = {"Red", "Blue", "Yellow", "Green"}
For Each item As String In Colours
Console.WriteLine(Colours)
Next
End Sub
End Class
此外,如果我尝试它将是一个列表框,它将添加每个项目但它将执行4x4次。
例如,它会添加" Red"列表四次。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Colours() As String = {"Red", "Blue", "Yellow", "Green"}
For Each item As String In Colours
ListBox1.Items.AddRange(Colours)
Next
End Sub
End Class
再次感谢,不太确定我是否可以同时提出2个问题,但我认为既然他们是同一个问题,那就没关系
答案 0 :(得分:0)
而不是使用Colours
使用实际的item
:
For Each item As String In Colours
ListBox1.Items.Add(item)
Next
与您的Console.WriteLine
For Each item As String In Colours
Console.WriteLine(item)
Next