gpt4 book ai didi

c# - 是否有类似 ICollection 的接口(interface),但专为排序的集合设计?

转载 作者:太空狗 更新时间:2023-10-29 18:25:18 27 4
gpt4 key购买 nike

...或者我可以毫无问题地使用 ICollection 吗?

我的意思是,我不认为 ICollection 是为排序集合设计的,因为这可能会破坏为排序或未插入的 ICollection 对象设计的应用程序,但我不知道。

最佳答案

我会说 ICollection<T> Interface适用于排序集合类型的实现,因为排序集合可以被枚举、添加、删除、清除和检查其内容。

作为反例,IList<T> Interface可能不合适,因为与 ICollection 不同,它假定集合是一个列表,元素可以添加到特定位置,如果集合本身确定每个元素的位置,这就没有意义。

.NET Framework 中的排序集合类型(SortedList<TKey, TValue> ClassSortedDictionary<TKey, TValue> ClassSortedSet<T> Class)都实现了 ICollection 但没有实现 IList

关于c# - 是否有类似 ICollection<t> 的接口(interface),但专为排序的集合设计?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13131167/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com