可以使用 LINQ 创建过去 12 个月的列表吗?
我希望做这样的事情:
List<DateTime> last12 = new List<DateTime>(12);
last12.ForEach(t=>t.AddMonths(-{t.Index}));
但还没有完全弄清楚如何做 {t.Index}
部分...
这样的事情可能吗?
I was hoping to do something like this:
List<DateTime> last12 = new List<DateTime>(12);
last12.ForEach(t=>t.AddMonths(-{t.Index}));
But haven't quite figured out how to do the {t.Index}
part...
Is such a thing possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
目前尚不清楚您是否希望计算当前月份,但这将为您指明正确的方向,您可以根据需要进行相应的编辑。
It's not clear if you want the current month counted are not, but this will point you in the right direction which you can edit accordingly for your needs.
从技术上讲,Foreach 不是 Linq 方法。它作为 List 类中的具体方法存在,但不存在于任何接口中。
农产品(丹麦语)
Foreach is tecnically not a Linq-method. It exists as a concrete method in the List class, but not in any interface.
Produces (in danish)