Search code examples
c#genericsilisticollection

Why does not the generic counterparts of IList and ICollection have the same set of methods?


Is there a particular reason to why the generic counterparts of IList and ICollection do not have the same set of methods and properties? They seem to have moved them around.

Ex. IList<T> has

int IndexOf(T item);
void Insert(int index, T item);
void RemoveAt(int index);
T this[int index] { get; set; }

But IList has

int Add(object value);
void Clear();
bool Contains(object value);
int IndexOf(object value);
void Insert(int index, object value);
void Remove(object value);
void RemoveAt(int index);
bool IsFixedSize { get; }
bool IsReadOnly { get; }
object this[int index] { get; set; }

Solution

  • IList<T> implements ICollection<T>, so at least in the context of an IList<T> it doesn't matter which interface has what. As far as why, who knows what goes on in the minds of that crazy .NET team. However, it seems logical that a "collection" would need the methods to add, remove, check its contents, etc AS LONG AS those methods are not in the context of an indexed "list". Once you start talking about a list conceptually, you add indexing, which requires the indexer itself, and index-sensitive methods to add, remove and check for elements.