Arrays C# C# Console Foreach Statement

Use For Loop With Array in C#

For-loop.

With this loop we use indexes.

We have a start, and end, and increment expression.

We must then access the element from the array in an expression within the loop.

Here: We use a for-loop to iterate over a string array.

The length of this array is 2, so the valid indexes are 0 and 1.

Info: The variable “i” is set to each array index.

We can access multiple array elements if needed in a for-loop.

C# Code:

Output:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.