You can use the Aggregate Method to create a custom amount:
var result = collection.Aggregate(
Tuple.Create(false, 0),
(s, x) => Tuple.Create(x == something,
s.Item1 + (s.Item0 && (x == somethingElse) ? 1 : 0)),
s => s.Item1);
It works as follows:
Item accumulator
--------------- ---------------
(false, 0)
foo (false, 0)
something (true, 0)
bar (false, 0)
something (true, 0)
somethingElse (false, 1)
somethingElse (false, 1)
baz (false, 1)
---------------
Result: 1
source
share