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
Code diagram comparing struct and class memory allocation in .NET

Struct or Class: When to Use Which in C#

Struct or class? Most types in a framework should be classes, but there are some situations in which the characteristics of a value type make it more appropriate to use structs. Here are some things to consider: 馃憤 If your instances are small and short-lived, or commonly embedded in other objects, consider using a struct. 馃憥 However, be cautious when defining a struct. Only use it if the type represents a single value, is immutable, has an instance size under 16 bytes, and will not need to be boxed frequently. ...

December 15, 2023 路 1 min 路 125 words 路 Eduardo Potumati