Understanding IEnumerable vs ICollection in C#
When working with collections in C#, two interfaces are foundational: IEnumerable<T> and ICollection<T>. Knowing the difference between them is crucial for writing efficient, maintainable, and correct code. What is IEnumerable<T>? IEnumerable<T> is the most basic interface for collections in .NET. It allows forward-only iteration over a sequence of items. Key points: Example: Notice: IEnumerable doesn’t […]