Choosing Between IEnumerable and List in C#

diakingdev
1 min readFeb 22, 2023

When to Use Each IEnumerable and List

IEnumerable

Use IEnumerable when you need to work with a collection of items, but you don't necessarily need to know how many items are in the collection or be able to access them randomly.

IEnumerable<int> numbers = new List<int> { 1, 2, 3, 4, 5 };

foreach (int number in numbers)
{…

--

--