foreach

The C# loop that asks a collection for its enumerator and hands you one item at a time.

In more detail

It works with anything that implements IEnumerable<T>, and pulling items is what triggers a deferred LINQ query. await foreach does the same over an IAsyncEnumerable<T>, awaiting between items.

Example

foreach (var qty in orders) Console.Write(qty);

Related terms

Taught in

References