简体   繁体   English

如何按dayofWeek c#对日期列表进行分组

[英]How to group list of date by a dayofWeek c#

I would like to group by a List by a DayOfWeek (and time of this DayOfWeek).我想按 DayOfWeek(以及 DayOfWeek 的时间)按列表分组。 For example a week is not from Monday 00:00 until Sunday 24:00, but from Tuesday 12:00 until the next Tuesday 11:59.例如,一周不是从周一 00:00 到周日 24:00,而是从周二 12:00 到下周二 11:59。 How could I group by this list?我怎么能按这个列表分组?

internal class ChartData
{
   public DateTime Date { get; set; }
   public int Value { get; set; }
}

Use System.Linq GroupBy.使用 System.Linq GroupBy。

var list = new List<ChartData>();
var grouped = list.GroupBy(d => GetWeekNumber(d.Date));

You can implement GetWeekNumber(DateTime date) to provde a sequential number depending on which week the ChartData belongs to.您可以实现 GetWeekNumber(DateTime date) 以根据 ChartData 所属的周提供序列号。 The implementation depends on what exactly you want to achieve.实现取决于您究竟想要实现什么。

You need to provide more example data.您需要提供更多示例数据。 But maybe it helps但也许它有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM