[英]List<T> derived from IList<T> and from IEnumerable<T>, useless?
From mscorlib.dll: 来自mscorlib.dll:
public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
{..}
public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>
{...}
Why List<T>
have to explicitly derived from ICollection<T>, IEnumerable<T>, IEnumerable,
in addition of derived from IList<T>
which itself derived from ICollection<T>, IEnumerable<T>, IEnumerable
? 为什么
List<T>
必须显式派生自ICollection<T>, IEnumerable<T>, IEnumerable,
另外还要派生自IList<T>
,它本身派生自ICollection<T>, IEnumerable<T>, IEnumerable
?
Don't trust decompiled code to be an accurate representation of the original source code. 不要相信反编译代码是原始源代码的准确表示。
The original source code contains only 原始源代码仅包含
public class List<T> : IList<T>, System.Collections.IList, IReadOnlyList<T>
So yes, you're right that List<T>
doesn't need to be explicitly derived from ICollection<T>
and others. 所以是的,你是正确的,
List<T>
不需要从ICollection<T>
和其他人明确派生。 It isn't. 事实并非如此。
The object browser or Reflector or similar don't have the source code, they have metadata to work with. 对象浏览器或Reflector或类似物品没有源代码,它们具有要使用的元数据。 Its not easy to know inspecting that information if a type implements directly an interface or not, so the easy option, because the ultimate goal is documentation, is to simply show all interfaces even if some are redundant.
如果类型直接实现接口,那么检查该信息并不容易,因此最简单的选择,因为最终目标是文档,即使有些冗余,也只是显示所有接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.