Mid From PDF Collections C# Collections

What does ICollection<T> provide, and how does it differ from IEnumerable<T>?

Short answer: ICollection<T> extends IEnumerable<T> and adds features like: Counting (Count property) Adding and removing items (Add, Remove) Checking for existence (Contains) Difference: IEnumerable<T> is read-only and forward-only iteration. ICollection<T> adds modification capabilities.

Example code

ICollection<int> numbers = new List<int>(); numbers.Add(5); numbers.Remove(5); Console.WriteLine(numbers.Count); Real-world use case: Use ICollection<T> when you need to manipulate the collection (add/remove items), such as managing an in-memory cart of products in a shopping application.

Real-world example (ShopNest)

In ShopNest, an order page loads products with List<Product> so you can Add items to the cart and access them by index. Use IEnumerable<T> when you only need to loop (for example, printing invoice lines).

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details