I am writing an Excel exporter for a bespoke application I am creating, and I have a question about LINQ grouping in C#.
Basically, this new Excel exporter class is
I tried like this (and it's working :) )
@foreach (var years in _dateRange.GroupBy(y => y.Year))
{
@years.Key
foreach (var months in years.GroupBy(m => m.Month))
{
@CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(months.Key)
foreach (var weeks in months.GroupBy(w => w.AddDays(-(int)w.DayOfWeek)))
{
@weeks.Key.ToString("dd-MMM-yy")
}
}
}