我不知道我非常理解下面的例子是如何工作的。它來自於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
?