本文介绍了[UWP]使用linq在C#列表中的两个日期之间获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个列表,其中包含开始日期,结束日期,姓名,位置等数据。 现在我想写一个像我想要的条件获取数据,如果,datetime.Today在事件startdate和结束日期之间,那么它应该将数据获取到该条件的正在进行的事件列表 如果event_startdate是lessthan datetime.Today然后它应该获取数据到pastevents列表。 id事件开始日期大于datetime.Today然后它应该获取数据到Upcommingevents列表。 /> 我为这样的Ongoingevents写了一个条件,它没有正确得到结果, Iam having a list which contains data like a startdate , end date, name, location etc..Now i want to write a condition like i want to get data if, the datetime.Today is between event startdate and end date then it should get the data to Ongoing events list for that true condition also if event_startdate is lessthan datetime.Today then it should get data to pastevents list.also id event start date is greater than datetime.Today then it should get data to Upcommingevents list.I wrote a condition for Ongoingevents like this , it is not getting the results correctly,indexlist = saveList.Where(i => Convert.ToDateTime(i.event_startdate) <= DateTime.Today).Union(indexlist.Where(i => Convert.ToDateTime(i.event_endDate) >= DateTime.Today)).ToList(); For Upming活动 For Upcomming Eventsindexlist = saveList.Where(i => Convert.ToDateTime(i.event_startdate) > DateTime.Today).ToList(); 过去活动 For Past events indexlist = saveList.Where(i => Convert.ToDateTime(i.event_startdate) < DateTime.Today).Union(indexlist.Where(i => Convert.ToDateTime(i.event_endDate) < DateTime.Today)).ToList(); 如何纠正陈述并获得正确的结果 How to correct the statements and get the correct resultspublic class Event_Detail_Content { public string event_name { get; set; } public string event_location { get; set; } public string event_startdate { get; set; } public string event_endDate { get; set; } public int count { get; set; } }public sealed partial class eventspage:page{List<Event_Detail_Content> indexlist = new List<Event_Detail_Content>();List<Event_Detail_Content> saveList = new List<Event_Detail_Content>();} 在eventspage类中,以上所有语句都是写的。 请帮帮我。 我尝试了什么: IN the eventspage class all athe above statements are written.Please help me.What I have tried:indexlist = saveList.Where(i => Convert.ToDateTime(i.event_startdate) <= DateTime.Today).Union(indexlist.Where(i => Convert.ToDateTime(i.event_endDate) >= DateTime.Today)).ToList(); 对于Upcomming活动 For Upcomming Eventsindexlist = saveList.Where(i => Convert.ToDateTime(i.event_startdate) > DateTime.Today).ToList(); 过去活动 For Past events indexlist = saveList.Where(i => Convert.ToDateTime(i.event_startdate) < DateTime.Today).Union(indexlist.Where(i => Convert.ToDateTime(i.event_endDate) < DateTime.Today)).ToList(); 推荐答案 indexlist = saveList.Where(i = Convert.ToDateTime(i.event_startdate) <= DateTime.Today && Convert.ToDateTime(i.event_startdate) >= DateTime.Today).ToList(); b $ b indexlist = saveList.Where(i => Convert.ToDateTime(i.event_startdate) <= DateTime.Today).Union(indexlist.Where(i => Convert.ToDateTime(i.event_endDate) >= DateTime.Today)).ToList(); indexlist = saveList.Where(i => Convert.ToDateTime(i.event_startdate) < DateTime.Today).Union(indexlist.Where(i => Convert.ToDateTime(i.event_endDate) < DateTime.Today)).ToList(); It正在展示OnGoing活动(例如:如果活动于2016年7月4日开始并于2016年7月7日结束,则不应在过去的活动中显示,因为该活动仍在继续)。你可以帮我吗。It is showing the OnGoing events also(for Ex: If an event starts on 4th July 2016 and ends on 7th July 2016, it should not be shown in Past events, because the event is stillcontinuing). Can u help me in this. indexlist = saveList.Where(i = Convert.ToDateTime(i.event_startdate) <= DateTime.Today && Convert.ToDateTime(i.event_startdate) <= DateTime.Today).ToList(); i认为它会对你有所帮助i think it will help you exactly 这篇关于[UWP]使用linq在C#列表中的两个日期之间获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 02:49