Is there an interface like ICollection<t>, but designed for sorted collections?

心已入冬 提交于 2019-12-22 04:31:42

问题


...or can I use ICollection with no problem?

I mean, I don't think ICollection was designed for Sorted collections because that could break an application designed for sorted or unserted ICollection objects, but I don't know.


回答1:


I'd say the ICollection<T> Interface is suitable for implementation by sorted collection types, because a sorted collection can be enumerated, added to, removed from, cleared and checked for its contents.

As a counter-example, the IList<T> Interface is probably not suitable, because unlike ICollection<T> it assumes that the collection is a list where the elements can be added at specific positions, which doesn't make sense if the collection itself determines the position of each element.

The sorted collection types in the .NET Framework (the SortedList<TKey, TValue> Class, SortedDictionary<TKey, TValue> Class, and SortedSet<T> Class) all implement ICollection<T> but not IList<T>.



来源:https://stackoverflow.com/questions/13131167/is-there-an-interface-like-icollectiont-but-designed-for-sorted-collections

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!