«^»
7.1. foreach statements

With a foreach statement, you can visit each element of a collection. For example, the above for statement:

for (int tIndex = 0; tIndex<pValues.Length; tIndex++)
{
    if (pValues[tIndex]==pTestValue)
    ...

can instead be written as:

foreach (int tValueFound in pValues)
{
    if (tValueFound==pTestValue)
    ...

A foreach statement can be used for any type that implements the IEnumerable interface:

public interface IEnumerable
{
    IEnumerator GetEnumerator();
}

In Java, the equivalent method to GetEnumerator is called iterator. The IEnumerator interface is:

public interface IEnumerator
{
    bool MoveNext();
    object Current{ get; }
    void Reset();
}

In Java, the equivalent interface to IEnumerator is called Iterator.

The following types implement the IEnumerable interface:

You can also produce your own types that implement this interface.