VB.Net - Each...Next 循环

它为集合中的每个元素重复一组语句。 此循环用于访问和操作数组或 VB.Net 集合中的所有元素。

此循环构造的语法是 −

For Each element [ As datatype ] In group
   [ statements ]
   [ Continue For ]
   [ statements ]
   [ Exit For ]
   [ statements ]
Next [ element ]

示例

Module loops
   Sub Main()
      Dim anArray() As Integer = {1, 3, 5, 7, 9}
      Dim arrayItem As Integer
     'displaying the values
      
      For Each arrayItem In anArray
         Console.WriteLine(arrayItem)
      Next
      Console.ReadLine()
   End Sub
End Module

当上面的代码被编译并执行时,会产生以下结果 −

1
3
5
7
9

❮ vb.net_loops.html