Export (0) Print
Expand All

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)
{
    System.Console.WriteLine(element);
}

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

Community Additions

ADD
Show:
© 2014 Microsoft