This documentation is archived and is not being maintained.

How to: Iterate Through an Array

Visual Studio 2008

This example uses the foreach statement to access and display items of an array.

int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9};
foreach (int element in numbers)

Copy the code and paste it into the Main method of a console application.