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>
看一下这个:
我的问题是:
如果grouped
包含项目(实现IEnumerable
),为什么它的类型是GroupedEnumerable
而不是 Enumerable
?
IEnumerable <System.Linq.IGrouping<string,ConsoleApplication15.Fruit>>
为什么他们创建了一个新的类型,即
GroupedEnumerable
?