小编Shi*_*rin的帖子

为什么 IList<T> 不只从 ICollection<T> 继承?

有趣的是,当我IList<T>在 Visual Studio 中查看 的定义时,它与 GitHub 上的源代码并不相同。

在此处输入图片说明

IList<T>

public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
Run Code Online (Sandbox Code Playgroud)

ICollection<T>

public interface ICollection<T> : IEnumerable<T>, IEnumerable
Run Code Online (Sandbox Code Playgroud)

鉴于ICollection<T>已经包含IEnumerable<T>以及IEnumerable为什么IList<T>需要包含它们。不能简化如下吗?

public interface IList<T> : ICollection<T>
Run Code Online (Sandbox Code Playgroud)

我试图理解这个长接口链接背后的逻辑。

您可以查看下面的源代码以查看差异。

https://github.com/microsoft/referencesource/blob/5697c29004a34d80acdaf5742d7e699022c64ecd/mscorlib/system/collections/generic/ilist.cs#L37

.net c# oop inheritance

18
推荐指数
2
解决办法
1568
查看次数

标签 统计

.net ×1

c# ×1

inheritance ×1

oop ×1