Share via


How to: Iterate Through an Array

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

Example

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

Compiling the Code

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

See Also

Concepts

C# Language Primer

Other Resources

Visual C# Express