我不知道我非常理解下面的例子是如何工作的。它来自于C#4.0,在果壳中。C#LINQ/Object Initializers来自C#4.0的简单例子
class Program
{
static void Main(string[] args)
{
string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" };
IEnumerable<TempProjectionItem> temp =
from n in names
select new TempProjectionItem
{
Original = n,
Vowelless = n.Replace("a", "").Replace("e", "").Replace("i", "")
.Replace("o", "").Replace("u", "")
};
IEnumerable<string> query = from item in temp
where item.Vowelless.Length > 2
select item.Original;
foreach (string item in query)
{
Console.WriteLine(item);
}
}
class TempProjectionItem
{
public string Original;
public string Vowelless;
}
}
IEnumerable
是一个接口,不是吗?什么样的对象是temp
和query
?为什么TempProjectionItem
不需要执行IEnumerable
?