如何:在 Visual Basic 中循环访问集合

更新:2007 年 11 月

您可以使用 For Each 循环来循环访问集合中的每个元素。

示例

下面的示例使用 For Each...Next 语句 (Visual Basic) 访问集合中的每一项。

Dim testCollection As New Microsoft.VisualBasic.Collection()
' The collection is empty until you add one or more items to it.
For Each collectionItem As Object In testCollection
    ' Perform desired processing on each item.
Next collectionItem

编译代码

此示例需要:

  • System 命名空间的访问权限。

请参见

任务

如何:添加、删除和检索集合中的项

概念

Visual Basic 中的集合

参考

For Each...Next 语句 (Visual Basic)