foreach Loop

A loop that visits each item in a collection or sequence.

What is foreach Loop in C#?

foreach Loop — A loop that visits each item in a collection or sequence.

class PetRegistry
{
    int CountNames(string[] pets)
    {
        int count = 0;

        foreach (string pet in pets)
        {
            count++;
        }

        return count;
    }
}

Level: Apprentice · More C# terms at this level

Updated