假设我有以下代码:
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 接口的类型的实例,但在这种情况下,它是 Developer 类的用户定义类型
示例代码取自 Microsoft .NET Framework Book 中的 LINQ。