dotnet / dotnet/runtime

[API Proposal]: Implement IList<bool> on BitArray

Open
#121,708 6 comments 0 reactions 0 assignees View on GitHub
api-suggestion area-System.Collections
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Background and motivation

`System.Collections.BitArray` implements the non-generic `ICollection`, but not the generic `ICollection`.
This makes it harder to use with LINQ.

Since `BitArray` already supports indexed access, implementing `IList` would also be a natural extension.

### API Proposal

```diff
namespace System.Collections;

public sealed class BitArray : ICloneable, System.Collections.ICollection
+ System.Collections.Generic.IList
{
}
```

### API Usage

```csharp
var bitArray = new BitArray(Enumerable.Range(0, 100).Select(static x => (x & 1) == 0).ToArray());

// foreach (bool item in bitArray.OfType())
foreach (bool item in bitArray)
{
Console.WriteLine(item ? "even" : "odd");
}
```

### Alternative Designs

_No response_

### Risks

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.