为什么ICollection< T>实现ICollection? [英] Why doesn't ICollection<T> implement ICollection?
问题描述
IEnumerable< T>
实现 IEnumerable
。
但 ICollection< T>
不实现 ICollection
。
这是什么理由和/或只是一个监督?
What was the rationale for this and/or was it just an oversight?
推荐答案
正如Nick所说, ICollection
几乎没用。
As Nick said, ICollection
is pretty much useless.
这些界面只有他们的名字相似, CopyTo
和 Count
是唯一的共同属性。 添加
,删除
,清除
,和
IsReadOnly
,而 IsSychronized
和 SyncRoot
已被删除。
These interfaces are similar only by their name, CopyTo
and Count
are the only properties in common. Add
, Remove
, Clear
, Contains
and IsReadOnly
have been added while IsSychronized
and SyncRoot
have been removed.
本质上, ICollection< T>
是可变的, ICollection
不是。
In essence, ICollection<T>
is mutable, ICollection
is not.
Krzysztof Cwalina 有更多关于此主题
ICollection< T>
似乎ICollection
,但它实际上是一个非常不同的抽象。我们发现ICollection
不是很有用。同时,我们没有代表一个读/写非索引集合的抽象。ICollection< T>
是这样的抽象,你可以说,在通用世界中,ICollection
没有完全相应的对等体;IEnumerable< T>
是最接近的。
ICollection<T>
seems likeICollection
, but it’s actually a very different abstraction. We found thatICollection
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 thatICollection
does not have an exact corresponding peer in the generic world;IEnumerable<T>
is the closest.
这篇关于为什么ICollection< T>实现ICollection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!