2015-11-06 71 views
-2

即時通訊相當新的VB.NET,即時通訊嘗試找出爲什麼它會出現在下面的代碼的第一部分中的System.string [],還在第二部分即時知道爲什麼值快到了4×4倍System.string []/listbox問題VB.NET

這裏是我的代碼

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 

另外,如果我嘗試將一個列表框,它會添加每個項目,但它會做4×4倍。

因此,例如它會在列表中添加四次「紅色」。

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 

再次感謝,也不太清楚,如果我能在同一時間問兩個問題,但我想既然他們是八九不離十了同樣的問題,這將是確定

回答

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 
+0

謝謝隊友:)我應該猜到了,我也試過這個控制檯端,並通過添加「Items」它也工作了,再次感謝隊友:) – Merve

+0

不客氣! – Ric