为什么ICollection< T>实现ICollection? [英] Why doesn't ICollection<T> implement ICollection?

查看:115
本文介绍了为什么ICollection< T>实现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 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.

这篇关于为什么ICollection&lt; T&gt;实现ICollection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆