A comparison table or code snippet demonstrating List vs IEnumerable in C#

List<T> or IEnumerable<T> in C#: Which one to choose?

That classic question: List<T> or IEnumerable<T> in C#? Straight to the point: IEnumerable<T>: when you only need forward iteration. It also works with deferred execution, the basis of LINQ and ideal for handling large amounts of data without loading everything into memory. ICollection<T>: in addition to iteration, it allows you to add, remove, and count items, but without index access. IList<T>: includes everything from ICollection<T>, plus index-based access and the ability to insert/remove at specific positions. List<T>: the concrete implementation of IList<T>, the class you usually use to instantiate a list. Why does this matter? Whenever possible, use the minimal required interface. Clear contracts reduce coupling and make your code more flexible and easier to maintain. ...

November 15, 2025 路 1 min 路 125 words 路 Eduardo Potumati
A code comparison showing a foreach loop converted into a LINQ expression

Convert a foreach Loop to LINQ

Convert a foreach loop to LINQ LINQ transforms a query into a first-class language construct in C#. It can reduce the amount of code, enhance readability, and enable similar query expression patterns across different data sources. 馃憠 Adapted from my original post on LinkedIn .

November 15, 2024 路 1 min 路 45 words 路 Eduardo Potumati