开发者

Is there any elegant way in LINQ to bucket a collection into a set of lists based on a property

i have a collection of cars. I want to bucket this into separate lists by a property of the car . . .lets say brand.

So if i have a collection of some Ford, some Chevy, some BMW, etc, i want a seperate list for each of those buckets.

something like:

IEnumberable<Car> myCarCollection = GetCollection();

List<IEnumera开发者_开发技巧ble<Car>> buckets = myCarCollection.BucketBy(r=>r.Brand)

does something exist like this or do i need to do this "manually" through loops


return myCarCollection.GroupBy(r => r.Brand);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜