有一个日期引用 UserJoinDate 和日期列表 List FriendsJoined 我想计算有多少 friend 在 UserJoinDate 之前加入了服务,以及有多少 friend 在同一时间或之后加入。
我写了以下几行,但它不起作用:
List<DateTime> joinersDates = getJoinersDates();
FriendsJoinedBeforeCount = joinersDates .Where(x => x < UserJoinDate).Count();
FriendsJoinedAfterCount = joinersDates .Where(x => x >= UserJoinDate).Count();
有谁知道如何计算 joinersDates 列表中有多少日期在 UserJoinDate 之前以及有多少相同或之后?
编辑
这是来自 ImmediateWindow 的副本:
churnersDates.Count( x => x > UserChurnDate)
Expression cannot contain lambda expressions
UserJoinDate 是日期时间
示例:
UserJoinDate = 9.11.2010 0:30:00
(该值复制自日期:{9.11.2010 0:00:00} 天:9 星期几:星期二 年中某日:313...)
和
joinersDates.First() = 17.5.2011 0:30:00
谢谢!
最佳答案
尝试分别使用 DateTime 的 Year、Month 和 Day 属性进行比较,如下所示;
FriendsJoinedBeforeCount = joinersDates .Where(x => (x.Year < UserJoinDate.Year) && (x.Month< UserJoinDate.Month) && (x.Day < UserJoinDate.Day)).Count();
关于c# - 如何将日期时间变量与 lambda 表达式进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11044957/