【发布时间】:2013-12-11 20:27:45
【问题描述】:
我有以下代码;
'list of dates
List<DateTime> oAllDates = new List<DateTime>();
// Imagine we are adding DateTime objects with the following values.
oAllDates.Add("2013-11-01");
oAllDates.Add("2013-11-02");
oAllDates.Add("2013-11-03");
...
oAllDates.Add("2013-11-30");
List<DateTime> MyDates = new List<DateTime>();
MyDates.Add("2013-11-03");
如果 MyDates 中的任何日期出现在 oAllDates 列表中,我想得到一个布尔结果。我可以使用以下
foreach (DateTime dtDate in oAllDates)
{
foreach (DateTime myDate in MyDates)
{
...
}
}
有没有更好的方法使用 LINQ 来实现这一点。另外,我有一个类似的列表
List<int> MyDaysByName = new List<int>();
MyDaysByName.Add(1); //sunday
MyDaysByName.Add(5); //thursday
我想在 oAllDates 中查找周日或周四的任何日期?
【问题讨论】:
-
oAllDates的结构是什么?你有DateTime类型属性吗? -
你到底是怎么做到的
List<DateTime> oAllDates = new List<oAllDates>();? -
我建议您单独问第二个问题,以便其他用户受益
-
但我的第二个问题仍然是使用相同的 oAllDates 列表
标签: c# linq list datetime compare