C# Linq or Lambda expression Group by Week IEnumerable list with date field

后端 未结 6 1386
梦如初夏
梦如初夏 2021-01-01 04:53

I am trying to do a query to an IEnumerable to group by week, for example:

Project(Name, DateStart,ID)

I have

6条回答
  •  时光说笑
    2021-01-01 05:04

    You can use the GetWeekOfMonth extension posted here:

    and then do something like:

            var groups = projects.GroupBy(p => p.Start.GetWeekOfMonth());
    
            foreach (var group in groups)
            {
                Console.WriteLine("Week {0}", group.Key);
                foreach (var project in group)
                {
                    Console.WriteLine("\t{0} | {1:dd/MM/yyyy} | {2}", 
                         project.Name, project.Start, project.Id);
                }
            }
    

提交回复
热议问题