为什么 Enumerable.Except 可以用于 C# 中的字符串数组?

Ler*_*rve 3 c# linq extension-methods

例子

以下是我在Pete on Software博客上找到的代码示例:

var listThree = new string[] { "Pete", "On", "Software" };  
var listFour = new string[] { "Joel", "On", "Software" };  
stringExcept = listThree.Except(listFour);
Run Code Online (Sandbox Code Playgroud)

代码编译并运行。到目前为止,一切都很好。

问题

但是,我不明白为什么它有效。

那么,谁能解释为什么我可以Enumerable.Except在字符串数组上使用?

也许,如果有人可以解释如何阅读签名Enumerable.Except并给我一个代码示例,我会很清楚:

public static IEnumerable<TSource> Except<TSource>(
    this IEnumerable<TSource> first,
    IEnumerable<TSource> second
)
Run Code Online (Sandbox Code Playgroud)

我知道的

我知道泛型和扩展方法的概念。但显然还不足以理解上面的代码示例。我也已经使用过一些基本的 Linq 查询。

dev*_*tal 6

Except是一个扩展方法,它扩展任何实现IEnumerable<T>. 这包括实现IEnumerable<T>.

链接页面上的注释解释了为什么文档没有显示System.Array实现IEnumerable<T>

在 .NET Framework 2.0 版中,Array 类实现System.Collections.Generic.IList<T>System.Collections.Generic.ICollection<T>System.Collections.Generic.IEnumerable<T>泛型接口。这些实现在运行时提供给数组,因此对文档构建工具不可见。因此,泛型接口不会出现在 Array 类的声明语法中,并且不存在只能通过将数组强制转换为泛型接口类型(显式接口实现)才能访问的接口成员的参考主题。将数组转换为这些接口之一时要注意的关键一点是添加、插入或删除元素的成员会抛出NotSupportedException