c# - Object 是否实现了 IEnumerable 接口(interface) C#?

标签 c# linq

假设我有以下代码:

using System;
using System.Linq;
using System.Collections.Generic;
public class Developer 
{
    public string Name;
    public string Language;
    public int Age;
}

class App {
    static void Main() {
        Developer[] developers = new Developer[] {
            new Developer {Name = "Paolo", Language = "C#"},
            new Developer {Name = "Marco", Language = "C#"},
            new Developer {Name = "Frank", Language = "VB.NET"}};
        var developersUsingCSharp = from d in developers
                                    where d.Language == "C#"
                                    select d.Name;
        foreach (var item in developersUsingCSharp) {
            Console.WriteLine(item);
        }
    }
}

我没有明确实现 IEnumerable<T>界面。我的问题是 from 子句将采用实现 IEnumerable 接口(interface)的类型的实例,但在这种情况下,它是 Developer 类的用户定义类型

示例代码取自 Microsoft .NET Framework Book 中的 LINQ。

最佳答案

System.Array (这是您在使用 Developer[] 表示法时创建的,实现 IEnumerable

关于c# - Object 是否实现了 IEnumerable 接口(interface) C#?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17257554/

相关文章:

C# 嵌套类需要实例化吗?

c# - 是否可以在不包含 System.Linq 命名空间的情况下使用 Linq 和 lambda?

c# - 根据特定条件选择用户(如果列表中存在)

c# - 如何在 MySQL 的 ASP.NET C# 应用程序中使用微软企业库

c# - 使用 MVC3 创建和编辑字符串集合

c# - 循环浏览 chrome 选项卡并根据网址关闭页面

c# - 为什么第一个 linq 的执行速度比第二个快 20 倍 [获取最大值]

asp.net-mvc - 如何找到所有以 a 或 â 开头的项目?

c# - 简化在列表中定位元素,可能使用 LINQ

c# - 如何将类型传递给用户控件