Re:Microfeatures I'd like to see in more languages
by int_19h on Friday January 06, 2023 @05:26PM
(#34282167)
All standard .NET collections with defined order and O(1) indexing support indexing backwards.
And no, it's not possible to do this using an extension method, unfortunately - there are no extension properties or indexers in C# (yet; it's something that keeps coming up). But then again, if and when they add extension indexers, this arrangement with a custom type is what'd allow you to write one that does backwards indexing on a collection type that doesn't support it out of the box.
And it mihjt be possible to add a static method to array to index backwards yourself (Can't remember what they are called, but look and act like methods on the object but aren't).