有一个日期参考UserJoinDate和日期列表列出friendsJoined我想计算在UserJoinDate之前加入服务的朋友数量,以及同时或以后加入服务的朋友数量。

我写了以下几行,但不起作用:

List<DateTime> joinersDates = getJoinersDates();
FriendsJoinedBeforeCount = joinersDates .Where(x => x < UserJoinDate).Count();
FriendsJoinedAfterCount = joinersDates .Where(x => x >= UserJoinDate).Count();


有谁知道如何计算joinJoinDate列表中UserJoinDate之前的日期以及相同或之后的日期?

编辑

这是从InstantWindow复制:

churnersDates.Count( x => x > UserChurnDate)
Expression cannot contain lambda expressions


UserJoinDate是DateTime

例:

UserJoinDate = 9.11.2010 0:30:00


(该值是从日期:{9.11.2010 0:00:00}复制的
    一天:9
    DayOfWeek:星期二
    年份:313 ...)



joinersDates.First() = 17.5.2011 0:30:00


谢谢!

最佳答案

尝试以下代码:

List<DateTime> joinersDates = getJoinersDates();
FriendsJoinedBeforeCount = joinersDates.Count(x => x.ToUniversalTime() < UserJoinDate.ToUniversalTime());
FriendsJoinedAfterCount = joinersDates.Count - FriendsJoinedBeforeCount ;


或尝试使用Ticks属性:

List<DateTime> joinersDates = getJoinersDates();
FriendsJoinedBeforeCount = joinersDates.Count(x => x.ToUniversalTime().Ticks < UserJoinDate.ToUniversalTime().Ticks);
FriendsJoinedAfterCount = joinersDates.Count - FriendsJoinedBeforeCount ;

10-05 18:11