【发布时间】:2017-10-02 11:13:41
【问题描述】:
我想从
List<CardEffect> opponenteffect
这个代码块是我想出来的
int netPhysicalDamage = oponenteffect.FindAll(
ce => ce.type == CardEffect.Type.physical
).Sum(ce => ce.amount);
是否可以对单个 Linq 函数调用进行此操作?
我想从
List<CardEffect> opponenteffect
这个代码块是我想出来的
int netPhysicalDamage = oponenteffect.FindAll(
ce => ce.type == CardEffect.Type.physical
).Sum(ce => ce.amount);
编辑:“单 Linq 函数调用”不是一个好主意,让这个更好
Edit2:这个问题不是很好。我不熟悉linq,我认为这部分代码有问题。感谢您的关注。
【问题讨论】:
-
为什么“单一”LINQ 调用很重要?
-
FindAll不是 LINQ 方法,请改用Where。 -
@Enigmativity:其实他说的是“更好”,而不是更重要...
-
@musefan - 在他的问题中没有提到“更好”。他只是被问到是否有可能使这成为一个单一的 LINQ 函数调用。我在问为什么这很重要。
-
@Enigmativity OP,这就是为什么我没有使用@