gpt4 book ai didi

.net - 为什么 ICollection 不实现 ICollection?

转载 作者:行者123 更新时间:2023-12-03 09:30:35 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Why does IEnumerable<T> inherit from IEnumerable?

(4 个回答)


8年前关闭。



IEnumerable<T>实现 IEnumerable .
但是ICollection<T>未实现 ICollection .

这样做的理由是什么和/或这只是一个疏忽?

最佳答案

正如尼克所说,ICollection几乎没用。
这些接口(interface)仅在名称上相似,CopyToCount是唯一的共同属性。 Add , Remove , Clear , ContainsIsReadOnly已在 IsSychronized 时添加和 SyncRoot已被删除。
本质上,ICollection<T>是可变的,ICollection不是。
Krzysztof Cwalina有更多关于这个topic

ICollection<T> seems like ICollection, but it’s actually a very different abstraction. We found that ICollection was not very useful. At the same time, we did not have an abstraction that represented an read/write non-indexed collection. ICollection<T> is such abstraction and you could say that ICollection does not have an exact corresponding peer in the generic world; IEnumerable<T> is the closest.

关于.net - 为什么 ICollection<T> 不实现 ICollection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2353346/

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