The foreach statement ( For Each...Next in VB ) executes embedded statements for each element in a collection or array.
foreach ( itemType item in collection ) {
... statements ...
}
For Each item As itemType In Collection
... statements ...
Next
foreach ( item : itemType in collection ) {
... statements ...
} |
|
C# |
VB |
JScript |
The foreach loop is entered if there is at least one element in the group to enumerate. If so, the embedded statements are executed for each element in the group. When there are no more elements, the loop ends and control is passed to the statement after the foreach block.
The following example shows use of a foreach statement to display the CultureInfo names and currency formats for each supported culture in the .NET framework.
Show me
Below are links to further code examples that illustrate using the foreach loop in ASP.NET web forms.