Question

Reading up here, I undestand why it is not IList<T>. But why IList at all? It makes no sense to add to it, so it should be just an IEnumerable, or if you really want an indexer (no reason why), use a ReadOnlyCollection.

Was it helpful?

Solution

Take a look at NotifyCollectionChangedEventArgs.

It has NewStartingIndex and OldStartingIndex properties.

So the design is based on Indexable collections, I assume this is convenient for eg Listboxes.

OTHER TIPS

Indexing is desirable for list virtualisation scenarios.

IList is the simplest collection interface that provided indexed access to elements. ReadOnlyCollection is a concrete class and thus far more limiting to implementors.

I think that in case of INotifyCollectionChanged you often need to perform a look-up for the components by their names (since the properties are stored as strings there), therefore it is essential to have an indexer that takes strings (and the underlying structure should probably be something like HashTable).

On MSDN webpage you can find the following recommendation:

If you have an advanced scenario and want to implement your own collection, consider using IList, which provides a non-generic collection of objects that can be individually accessed by index and provides the best performance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top