# 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.

```csharp
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](https://www.ask-codey.com/glossary/subjects/c-sharp/apprentice)

Updated: September 27, 2026

Source: https://www.ask-codey.com/glossary/foreach-loop
