You can do this with Aggregate
, although it hurts a bit, and creates an additional object for each iteration:
var sums = scores.Aggregate(new { Sum = 0, Count = 0 }, (current, item) => new { Sum = current.Sum + item.Score * item.Fraction, Count = current.Count + item.Fraction });
Obviously, you could make this more efficient by creating a ValueTuple<T1, T2>
structural tuple, but as a structure.
EDIT: I agree with Petar's point - if that is all you need to do, then LINQ will not really help in this situation.
source share