为何IDictionary同时实现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>的reference source,您会发现实际实现仅实现ICollection< KeyValuePair< TKey,TValue>&gt ;:

public interface IDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>>
上一篇:Android添加依赖recycleview错误


下一篇:android – 房间找不到实现