Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 列表<;T>;源自IList<;T>;来自IEnumerable<;T>;,没用?_C#_Derived Types - Fatal编程技术网

C# 列表<;T>;源自IList<;T>;来自IEnumerable<;T>;,没用?

C# 列表<;T>;源自IList<;T>;来自IEnumerable<;T>;,没用?,c#,derived-types,C#,Derived Types,从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<

从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>
{...}
公共接口IList:ICollection、IEnumerable、IEnumerable
{..}
公共类列表:IList、ICollection、IEnumerable、IEnumerable、IList、ICollection、IReadOnlyList、IReadOnlyCollection
{...}

为什么
列表
必须显式派生自
ICollection,IEnumerable,IEnumerable,
,以及派生自
IList的
,IList本身派生自
ICollection,IEnumerable,IEnumerable

不要相信反编译代码是原始源代码的准确表示

仅包含

公共类列表:IList、System.Collections.IList、IReadOnlyList

是的,
List
不需要显式派生自
ICollection
和其他。它不是。

对象浏览器或反射器或类似工具没有源代码,它们有元数据可供使用。要知道类型是否直接实现接口并不容易,因此简单的选项,因为最终目标是文档,就是简单地显示所有接口,即使有些接口是冗余的


有关更多信息,请阅读。

否,这不是来自mscorlib.dll。mscorlib.dll不包含C#代码。这是你的反编译器向你展示的内容。请检查最终这只是你的反编译器的帮助。一次性告诉类实现了哪些接口非常有用。这种声明模棱两可,是“接口继承”用词不当的副作用。C#语法让它看起来太像是一种让你更富有的继承。这是一个用词不当的说法,因为这实际上会让你变得更穷,因为你需要做更多的工作来实现接口成员。功能,而不是bug。
public class List<T> : IList<T>, System.Collections.IList, IReadOnlyList<T>