Junior
From PDF
Collections
C# Collections
What is the role of the IList<T> interface in collections?
Short answer: IList<T> extends ICollection<T> and allows: Indexed access (like arrays) Inserting and removing at specific positions
Example code
IList<string> fruits = new List<string>(); fruits.Add("Apple"); fruits.Insert(0, "Banana"); // Insert at index 0 Console.WriteLine(fruits[1]); // Access by index Real-world use case: Use IList<T> when order matters and you need to access, insert, or remove elements at specific positions, like reordering tasks in a to-do list.
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
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png