计算在Linq C#内订阅结束的用户 [英] Count users where subscription end within month Linq c#
本文介绍了计算在Linq C#内订阅结束的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想统计用户的订阅结束日期在下个月之内:
I just want to count users where their subscription end date is within the coming month:
int Count = oUsers
.Where(x =>
0 < x.SubscriptionEnddate.Value.Subtract(DateTime.Now).Days < 30)
.Count();
但是它不起作用.
我想做的是 0<值< 30 .
推荐答案
使用&&
.时期.它是专为它设计的.
Use &&
. Period. It is where it is designed for.
您可以通过创建Between
扩展方法或将两个Where
子句连接起来来规避此问题,但实际上,为什么要在&&
上进行交易.但是,如果您坚持:
You can circumvent this by creating a Between
extension method, or concatenate two Where
clauses, but really, why trade that over &&
. But if you insist:
int c = oUsers
.Select(x=> x.SubscriptionEnddate.Value.Subtract(DateTime.Now.AddDays(30)).Days)
.Where(d => 0 < d)
.Where(d => d < 30)
.Count();
这篇关于计算在Linq C#内订阅结束的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文