gpt4 book ai didi

c# - 为什么 IDictionary 同时实现 ICollection 和 IEnumerable

转载 作者:行者123 更新时间:2023-11-30 15:16:14 25 4
gpt4 key购买 nike

我正在查看为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com