Fruit[] data = new[] {
new Fruit {Name = "Gala",Type = "Apple",Price = 0.75m,Quantity = 10},
new Fruit {Name = "Granny Smith",Type = "Apple",Price = 0.80m,Quantity = 7},
new Fruit {Name = "Tasty",Type = "Strawberries",Price = 1.90m,Quantity = 20}
};
var grouped = from fruit in data
group fruit by fruit.Type;
grouped
类型是:System.Linq.GroupedEnumerable<ConsoleApplication15.Fruit,string,ConsoleApplication15.Fruit>
看看它:
我的问题 :
如果分组包含项目(实现 ienumerable) - 为什么它的类型是GroupedEnumerable
而不是
IEnumerable <System.Linq.IGrouping<string,ConsoleApplication15.Fruit>>
他们为什么要创建一个新的 Type aka GroupedEnumerable
?