Dim aList as New List(Of String)aList.Add("one") aList.Add("two") aList.Add("three") For Each str As String in aList System.Console.WriteLine(str)Next
产生以下输出:
one two three
另一种选择是遍历每个元素的索引:
Dim aList as New List(Of String)aList.Add("one") aList.Add("two") aList.Add("three") For i = 0 toaList.Count- 1 'We use "- 1" because a list uses 0 based indexing. System.Console.WriteLine(aList(i)) Next