Linq – Multiple Group By

This has been bugging me for a LONG time!

I’ve finally found an example of how to group by multiple values using LINQ:
IList doc_infos = new List();

doc_infos.Add(new doc_info { region = "UK", price = 100, currency = "US" });
doc_infos.Add(new doc_info { region = "US", price = 100, currency = "US" });

var docs = doc_infos.GroupBy(x => new { x.price, x.currency })
.Select(group => new { d = group.Key, Count = group.Count() });

For more examples, have a look here.

Popularity: 3% [?]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>