In C# and Vb.net,is any way without iterating by loop a bitarray to check contins any true or false value (Dotnet 2.0) ?
I doubt there's any way you could do it without a loop under the hood (as a BitArray
can be arbitrarily long, unlike BitVector32
), but if you just don't want to write it yourself:
var hasAnyTrue = input.Cast<bool>().Contains(true);
var hasAnyFalse = input.Cast<bool>().Contains(false);
If you are using the BitArray class from System.Collections you can use the following code to determine if anything is true.
C# version
var anyTrue = myArray.Cast<bool>().Any(x => x);
VB.Net Version
Dim anyTrue = myArray.Cast(Of Boolean)().Any(Function(x) x)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With