C# Array For Loop

To loop over the elements of an Array using For Loop, initialize a variable for index, increment it during each iteration, and access element at this index during each iteration.

Refer C# For Loop tutorial.

Example

In the following example, we take a string array with three elements, and iterate over the elements of this array using For Loop.

Program.cs

using System;

namespace CSharpExamples {
    class Program {
        static void Main(string[] args) {
            string[] arr = {"apple", "banana", "cherry"};
            for (int index=0; index < arr.Length; index++) {
                Console.WriteLine(arr[index]);
            }
        }
    }
}

Output

apple
banana
cherry

Conclusion

In this C# Tutorial, we learned how to iterate over elements of an array using For Loop, with examples.