0Pricing
C# Academy · Lesson

Iterating Collections

Lists, arrays, dictionaries.

Collections You Can Iterate

Many C# types can be looped with foreach: arrays, List<T>, dictionaries, and more.

They all support iteration because they implement a shared interface. You don't need to know the details to use them.

Iterating an Array

Arrays have a fixed size set when created.

You can loop over an array of any element type the same way.

double[] prices = { 9.99, 4.50, 19.00 };
foreach (var p in prices)
{
    Console.WriteLine(p);
}

All lessons in this course

  1. The foreach Loop
  2. Iterating Collections
  3. break and continue
  4. Common Iteration Mistakes
← Back to C# Academy