I need to group by multiple properties by month and year in C# LINQ
This is my code:
public class Class1
{
public Nulla
If you have MoreLinq referenced you can use make Ivan's answer cleaner by using CountBy:
var result = listGoogleTimezone
.SelectMany(x => new[] { x.dt1, x.dt2 }
.Where(dt => dt != null)
.Select(dt => dt.Value))
.CountBy(x => new { Year = x.Year, Month = x.Month });
This will can you an IEnumerable where the TKey is an anonymous type with Year and Month and the int is the count.