How do I make a System.Collection.BitArray readonly? I looked for the follwing but without any success yet...
myBitArray.IsReadOnly = true;does not work as the property has only a getter.myBitArray.SetReadOnly()does not work as there is no such method.new BitArray(myBitArray, readonly: true)does not work as there is no such constructor overload.myBitArray.Clone(readonly: true)does not work as there is no such method overload.myBitArray.AsReadOnly()does not work as there is no such extension method.And neither is there a
BitArrayBuilder...
What am I missing?
(Am using .NET 4.8 to 6.0, multi-targeting)
CodePudding user response:
From the documentation of BitArray.IsReadOnly
This property is always false.
BitArray implements the IsReadOnly property because it is required by the System.Collections.IList interface.
That explanation seem a bit odd to me, since BitArray does not seem to implement IList, only ICollection. But that is the explanation given.
If you are in some particular need for a read only bitArray an option might be to create your own class or a wrapper.
