Open polijp opened 2 months ago
You often need to know how many bits are set to 1 in a BitArray. Presently, there are two ways to achieve that:
Adding a Cardinality property takes the advantage of the underlying int array. It could use the instrinsic BitOperations.PopCount() method.
namespace System.Collections; public class BitArray ... { public int PopCount => ... }
// Fancy the value var c = new BitArray(10); if (c.PopCount %2 ==0) do something; ### Alternative Designs _No response_ ### Risks _No response_
Tagging subscribers to this area: @dotnet/area-system-collections See info in area-owners.md if you want to be subscribed.
Background and motivation
You often need to know how many bits are set to 1 in a BitArray. Presently, there are two ways to achieve that:
Adding a Cardinality property takes the advantage of the underlying int array. It could use the instrinsic BitOperations.PopCount() method.
API Proposal
API Usage