C# 15 lets you add indexers to types you don't own via extensions
C# 15, shipping with .NET 11 in November, lets developers declare a this[...] indexer inside an extension block for types they cannot modify. Combined with Count and Slice, it enables ^1, ranges and list patterns; the feature was tested on the .NET 11 RC 1 SDK.
- Indexers are declared in an extension block with a named receiver
- Count and Slice unlock ^1, ranges and list patterns
- A type's own indexer always takes priority over an extension
- Extension indexers never apply to arrays or strings
Read next
Software