I have a list< item > of the following
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;
}
}
Which is just a parsed RSS feed, I now want to be able to query the List< item > to pull 开发者_StackOverflow中文版out items only with a PublishDate of today?
However I'm getting a bit lost... Can anyone shed any light please?
If I understand correctly the goal here is to strip off the time when comparing.
Extention Method syntax
var today = DateTime.Today;
items.Where( item => item.PublishDate.Date == today );
Query syntax
var today = DateTime.Today;
from item in items
where item.PublishDate.Date == Today
select item
DateTime today = DateTime.Today;
var todayItems = list.Where(item => item.PublishDate.Date == today);
List<Item> itemList = ...;
ListItem<Item> filtered items
= itemList.Where(it => it.PublishDate >= DateTime.Today).ToList()
精彩评论