我有一个 List<bool>
并希望对列表进行按位异或(以创建校验位)
这是我目前拥有的
List<bool> bList = new List<bool>(){true,false,true,true,true,false,false};
bool bResult = bList[0];
for( int i = 1;i< bList.Count;i++)
{
bResult ^= bList[i];
}
问:是否有
Linq
单线解决这个更优雅?
最佳答案
bool bResult = bList.Aggregate((a, b) => a ^ b);
关于c# - 对 List<bool> 的按位运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37986798/