A BinaryInteger<T>
is an integer of some bit-length. I'd like to use it to index an array.
Casting to an int isn't possible - I have to use int.CreateTruncating(i)
(or similar) at run-time to get an array index.
Is there a way to get array[]
to accept an IBinaryInteger<T>
as an index?
I know I could use a dictionary or similar but array has some other neat operations I'd like to use as well, like AsSpan
, CopyTo
, etc.
I'm on .NET 9.
IBinaryInteger<T>
et. al. are more than 20 years newer than the definition ofSystem.Array
, and something like 18 years newer than the interfaces inSystem.Collections.Generic
. Going back and changing APIs who break a lot of code...int.CreateTruncating(i)
?int
.