c# - 为什么 IDictionary<TKey, TValue> 同时实现 ICollection 和 IEnumerable

标签 c# interface implementation

我正在查看为 IDictionary<TKey, TValue> 生成的元数据接口(interface),我注意到它实现了

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

最佳答案

元数据显示了所有已实现的接口(interface),尤其是那些通过继承获得的接口(interface)。如果你查看 reference sourceIDictionary<TKey, TValue> , 你看到实际的实现只实现了 ICollection<KeyValuePair<TKey, TValue>> :

public interface IDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>>

关于c# - 为什么 IDictionary<TKey, TValue> 同时实现 ICollection 和 IEnumerable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50170629/

相关文章:

c# - 使用 linq 对行求和

c# - 在 SQL 数据库和 EF6 中保存标志枚举。这可能吗?

c# - 确定哪个 .net 程序集加载了另一个

java - 抽象类方法头与接口(interface)

c++ - 公共(public)接口(interface)方法的私有(private)实现

java - 如何强制第 3 方实现/继承类在 java 中运行泛型方法?

c# - 有什么方法可以强类型化控件的 Tag 属性吗?

java - 一个接口(interface),其中所有方法具有多个实现类,每个实现类实现该接口(interface)中方法的子集

java - 接口(interface),如果不是所有实现都使用所有方法怎么办?

c# - 带接口(interface)的访问修饰符