Bitwise operation to a List<bool>

bool bResult = bList.Aggregate((a, b) => a ^ b);

Another one line solution (in addition to Buh Buh's one):

bool bResult = bList.Count(a => a) % 2 == 1;

when you xor a sequence of bool you actually want to return true if there're odd number of trues in the sequence


You can use Aggregate:

bool result = bList.Aggregate((res, b) => res ^ b);

This calls the lambda for every element except the first. res is the accumulated value (or the first element for the first call) and b the current value from the list.

Tags:

C#

Linq

List