Skip to content

BitArray should support Range-Indexer (RuntimeHelpers.GetSubArray<bool>) to get a range of Bits #108657

Open

Description

To make BitArrays more user-friendly and easier to use it would be nice if you could access Bits in a BitArray with a Range-Indexer. Like this: var firstTwoBits = bitArray[..2];

Example comparison with a List:

var bitArray = new BitArray(new bool[]{true, false, false});
var firstBit = bitArray[0];
var firstTwoBits = bitArray[..2]; // doesn't work :(
var lastBit = bitArray[^1];

var list = new List<int> { 1, 2, 3 };
var firstItem = list[0];
var firstTwoItems = list[..2]; // works fine!
var lastItem = list[^1];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions