Comment by neonsunset
1 year ago
[^n] indexing is mapped to an 'Index' struct by Roslyn which can then be applied to any array or list-shaped type (it either has to expose Index-accepting indexer, or a plain integer-based indexer and Count or Length property. There really isn't much to optimize away besides the bounds check since there are no object allocations involved.
A similar approach also works for slicing the types with range operator e.g. span[start..end].
No comments yet
Contribute on Hacker News ↗