我有一个清单< item>以下
public class Item
{
public string Link { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public DateTime PublishDate { get; set; }
public FeedType FeedType { get; set; }
public Item()
{
Link = "";
Title = "";
Content = "";
PublishDate = DateTime.Today;
FeedType = FeedType.RSS;
}
}
这只是一个已解析的RSS提要,我现在希望能够查询List< item>仅使用今天的PublishDate提取项目?
但是我有点迷失了......有人可以放任何光吗?
答案 0 :(得分:9)
如果我理解正确,这里的目标是在比较时剥离时间。
扩展方法语法
var today = DateTime.Today;
items.Where( item => item.PublishDate.Date == today );
查询语法
var today = DateTime.Today;
from item in items
where item.PublishDate.Date == Today
select item
答案 1 :(得分:4)
DateTime today = DateTime.Today;
var todayItems = list.Where(item => item.PublishDate.Date == today);
答案 2 :(得分:0)
List<Item> itemList = ...;
ListItem<Item> filtered items
= itemList.Where(it => it.PublishDate >= DateTime.Today).ToList()