c# - 为什么要字典实现了 ICollection 和 IEnumerable
问题描述
我正在查看为IDictionary<TKey, TValue>
接口生成的元数据,我注意到它实现了
public interface IDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable
这不是多余的吗?查看它的元数据ICollection<T>
表明它已经实现IEnumerable<T>, IEnumerable
为什么IEnumerable<T>
实施IEnumerable
,而ICollection<T>
没有实施ICollection
?
解决方案
元数据显示所有实现的接口,尤其是那些通过继承获得的接口。如果您查看 的参考源,IDictionary<TKey, TValue>
您会看到实际实现仅实现ICollection<KeyValuePair<TKey, TValue>>
:
public interface IDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>>
推荐阅读
- haskell - `State#` 的规范
- android - 从设备在 Firestore 上创建文档
- mysql - 在一个部门的所有项目中工作的员工
- c++ - 打印结构数组数据导致 Atmega 2560 重新启动
- android - 使用 firebase-firestore 会产生构建错误
- ruby-on-rails - Rails + React + 实时验证
- c# - 检索 Azure 数据工厂服务标识应用程序 ID
- python-3.x - 处理数据类型对象的数据框列的缺失数据
- javascript - HTML视频白平衡编辑
- cuda - 如果 CUDA 线程遇到错误,有没有办法终止主机和设备程序的执行?