c# - C#中所有的数组都实现了哪些接口(interface)?

标签 c# .net arrays interface-implementation

作为一名新的 .NET 3.5 程序员,我开始学习 LINQ,我发现了一些我以前没有注意到的非常基础的东西:

这本书声称每个数组都实现了IEnumerable<T> (显然,否则我们不能对数组上的对象使用 LINQ...)。当我看到这个时,我心想我从来没有真正想过这个,我问自己所有数组还实现了什么 - 所以我检查了 System.Array使用对象浏览器(因为它是 CLR 中每个数组的基类),令我惊讶的是,它没有实现 IEnumerable<T> .

所以我的问题是:定义在哪里?我的意思是,我如何才能准确判断每个数组实现了哪些接口(interface)?

最佳答案

来自documentation (强调我的):

[...] the Array class implements the System.Collections.Generic.IList<T>, System.Collections.Generic.ICollection<T>, and System.Collections.Generic.IEnumerable<T> generic interfaces. The implementations are provided to arrays at run time, and therefore are not visible to the documentation build tools.

编辑:正如 Jb Evain 在他的评论中指出的那样,只有向量(一维数组)实现通用接口(interface)。至于为什么多维数组不实现泛型接口(interface),我不太确定,因为它们确实实现了非泛型对应物(参见下面的类声明)。

System.Array类(即每个数组)也实现了这些非通用接口(interface):

public abstract class Array : ICloneable, IList, ICollection, IEnumerable, IStructuralComparable, IStructuralEquatable

关于c# - C#中所有的数组都实现了哪些接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4482557/

相关文章:

c# - 你如何找到调用者函数?

.net - 我们可以强制 XmlWriter 发出 <my-tag></my-tag> 而不是 <my-tag/> 吗?

.net - 请求超时HttpException是否导致w3wp.exe进程死亡或回收

javascript - 循环遍历 String 中的对象数组

c# - 涉及递归的 TPL 数据流未完成

c# - 编码 C# 类型以调用 C++ IDispatch 接口(interface)导致类型不匹配

c# - 如何加速 C# 中的数组克隆?

JavaScript Array join() 导致结果中出现空 (%00) 字符

java - 寻求有关实现堆数据结构的帮助

c# - Windows 窗体的 BackgroundWorker 替代品