【发布时间】:2014-08-24 01:52:44
【问题描述】:
我有以下对象:
internal class AlbumImage
{
internal string AlbumName { get; set; }
internal string ImagePath { get; set; }
internal DateTime DateTaken { get; set; }
}
有了这个,我有一个列表:
private List<AlbumImage> _albumImages;
我想根据拍摄日期对该列表进行分组。这个想法是,对于每个元素,将根据特定日期(预定义)检查拍摄日期,因此为了举例,假设我们使用 1980 年 1 月 1 日的日期。
我想将我的数据分组如下:
1 month
2 months
3 months
4 months
5 months
6 months
7 months
8 months
9 months
10 months
11 months
12 months
18 months
24 months
36 months
48 months
etc.
这个想法是,一年后,分组更改为 6 个月。
所以回到我 1980 年的日期,任何从 1980 年 1 月 1 日起 1 个月或更短的日期的 AlbumImages 元素,它们都应该在 1 个月分组中。任何从 1980 年 1 月 1 日开始的日期超过 1 个月但小于或等于 2 个月的 AlbumImages 元素,它们应该在 2 个月分组中。等等……
在 Linq 中这样做很简单吗???
【问题讨论】:
-
你有没有尝试过?当你展示你的努力而不是仅仅要求完整的解决方案时,这很好。
-
不,因为我不知道该怎么做。
标签: c# .net linq linq-to-objects