...或者我可以毫无问题地使用ICollection吗?
我的意思是,我认为ICollection并不是为排序集合而设计的,因为这可能会破坏专门为已排序或未排序的ICollection对象设计的应用程序,但我不确定。
我认为 ICollection<T>接口 适用于实现有序集合类型,因为有序集合可以被枚举、添加元素、删除元素、清空并检查其内容。
作为反例,IList<T>接口可能不适用,因为与ICollection<T>不同,它假设集合是一个列表,其中元素可以在特定位置添加,如果集合本身确定每个元素的位置,则这没有意义。
.NET Framework中的有序集合类型(SortedList<TKey, TValue>类、SortedDictionary<TKey, TValue>类和SortedSet<T>类)都实现ICollection<T>但不是IList<T>。
IOrderedEnumerable<TElement>
https://learn.microsoft.com/en-us/dotnet/api/system.linq.iorderedenumerable-1?view=netcore-3.1
public class SortedDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IDictionary, ICollection, IEnumerable {}
- L.B