我如何 LINQify 这个?
雷沙珀说我可以,但我不知道如何做。这种形式有几个例子:
foreach (ItemType Item in ListOfItems)
if (ConditionalInvolvingItem)
Total += ItemProperty;
当然,我可以根据条件创建一个子列表,然后对子列表中的项目求和,但这不会更清晰,而且运行速度会更慢。
Resharper says I can but I don't see how. There are several examples of the form:
foreach (ItemType Item in ListOfItems)
if (ConditionalInvolvingItem)
Total += ItemProperty;
Of course I could make a sublist on the conditional and then sum the items in the sublist but this would be no clearer and would run slower.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ReSharper 是一个方便的工具,但请记住,它的建议并不总是更高效或更不言自明。这里就是这种情况。这实在是一个折腾。我确信您心里已经有了 LINQ 语句,但我想这个示例应该是这样的:
ReSharper is a handy tool, but keep in mind its suggestions aren't always necessarily more performant or self-explanatory. Such is the case here. It's really a toss-up. I'm sure you already have a LINQ statement in mind, but I'd imagine this example would look as such: