Junior Collections

What is the role of the IList<T> interface in collections?

IList<T> extends ICollection<T> and allows:

  • Indexed access (like arrays)

Follow:

  • Inserting and removing at specific positions

Example:

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.

More from C# Programming Tutorial

All questions for this course