Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Code: Iterating Through an Array (Visual C#)

Visual Studio .NET 2003
 

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

Iteration Statements | foreach, in | Using foreach with Arrays | Using foreach with Collections | Arrays | Arrays Tutorial | General Language Example Topics

Show:
© 2015 Microsoft