I have this code
Dim sum As Integer = scores.Sum(Function(score) score.Fraction * score.Score)
Dim count As Integer = scores.Sum(Function(score) score.Fraction)
or in C#:
var sum=scores.Sum(score=>score.Fraction * score.Score);
var count=scores.Sum(score=>score.Fraction);
How can I merge these AND achieve that the collection is only enumerated once? I did find some examples but if I am not mistaken they still iterate the collection twice.
… My point is, why use LINQ at all – it’s meant to make certain things easier, but this is not easier with LINQ.