سؤال

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.

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top