A Range `..` operator is proposed for C# 7.3. This tracks compiler work for that feature. Proposals: - https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/ranges.cs - https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/index-range-changes.md See also some discussion elsewhere - https://github.com/dotnet/csharplang/issues/185 - http://khyperia.com/range.html - https://github.com/dotnet/roslyn/issues/7632 - https://github.com/dotnet/csharplang/issues/198 - https://github.com/dotnet/csharplang/blob/master/meetings/2017/LDM-2017-07-05.md#slicing - https://github.com/dotnet/csharplang/blob/master/meetings/2016/LDM-2016-11-01.md#slicing - https://github.com/dotnet/roslyn/issues/120 - https://github.com/dotnet/corefxlab/issues/1306 - https://github.com/dotnet/corefxlab/pull/1859 - dotnet/corefx#25220 - https://github.com/terrajobst/designs/blob/27a6b1c7df08ae42baa2d5f13bcd9d0e259b47e2/accepted/system-range/system-range.md ### Compiler - [x] Start work on a new feature branch - [x] New token `..` - [ ] Fit into operator precedence somewhere - [ ] Parser for range expressions - [ ] Built-in operator overloading - [ ] `Range operator ..(int, int)` - [ ] `LongRange operator ..(long, long)` - [ ] Requires some well-known APIs be present - [ ] Permit user-defined operator - [ ] Accepting and binding the syntax - [ ] Decide on some underlying special name - [ ] Overload the user-defined ones when applicable ### API questions - What is the name of the thing? - Closed interval, half-open interval, or start and count? - step? - Implements IEnumerable pattern (using value types)? - Conversions to array, List, IEnumerable, etc? - Constructor vs static factory methods - Is there a conversion (built-in or otherwise) from an int range to a long range? - Were the types ported to mono? https://github.com/mono/mono/issues/12020 ``` c# namespace System { public struct Range { public Range(int left, int right) ... } public struct LongRange { public LongRange(long left, long right) ... } } ``` - [ ] Supported in `Span<T>` and `ReadonlySpan<T>`? ``` c# Span<T> x = ...; Span<T> y = x.Slice([1..0]); ``` ### IDE - [x] ~~The `ForEachToFor` refactoring should recognize range syntax~~ (not applicable to new design) ### Open Issues - [x] Shall we support dropping one or more operands - `1..` - `..10` - `..` - [ ] Should we have two versions for half-open and closed intervals - Rust: `..` for half-open and and `...` for closed - Swift: `..<` for half-open and `...` for closed - [ ] Do we want to do something with arrays for `a[1..10]`? - [ ] Do we want to do something with pattern-matching?
A Range
..operator is proposed for C# 7.3. This tracks compiler work for that feature.Proposals:
See also some discussion elsewhere
Compiler
..Range operator ..(int, int)LongRange operator ..(long, long)API questions
Span<T>andReadonlySpan<T>?IDE
The(not applicable to new design)ForEachToForrefactoring should recognize range syntaxOpen Issues
1....10....for half-open and and...for closed..<for half-open and...for closeda[1..10]?