C# LINQ counting elements with DISTINCT -


i have collection of keyvaluepair items datetime key , string value. data looks like:

12/07/2013 - 10220 12/07/2013 - 10220 12/07/2013 - 12220 12/07/2013 - 11240 12/07/2013 - 15220 13/07/2013 - 23220 13/07/2013 - 35620 14/07/2013 - 15620 14/07/2013 - 15620 

i have list of how many items (distinct) i've each days. query result in a:

12/07/2013 - 4 13/07/2013 - 2 14/07/2013 - 1 

use group by

var dategrouped = dates.groupby(x => x.key)                        .select(x => new { date = x.key, values = x.distinct().count() }); 

Comments