Ranges would enable quick and easy navigation of integer ranges:
foreach(var item in 3..5)
Spec and discussion is here: dotnet/csharplang#185
@BillHiebert is it still planned for 7.3 or postponed?
@molinch the last information I have is that this feature didn't make the 7.3 deadline. The proposal referenced in this issue's description has the latest LDM discussion links. We will add a milestone and schedule this once the feature is merged into the roslyn master branch.
Changing the title, as this did not make the 7.3 release.
I've put together an outline for scenarios where these features are best used. These are a series of small features that would be great in the interactive experience:
. Find the median of a set of numbers.
. Calculate the moving average in a sequence.
. First N, Last N of a sequence.
Others are all similar in nature.
I'm moving this back to the backlog, pending C# 8 (and Range and Index) support in the try.net experience.
Some tidbits to explain from-end and exclusive-at-end behavior, which may be helpful:
In real world scenarios where constant indices are less common than computed ones, these properties and symmetries help avoid off-by-one errors and unnecessary +1/-1 adjustments.
The content created for this issue should be linked to from "What's new in .NET Core 3.0"
See #11641
Subscribing to this issue
@Thraka
I read @BillWagner 's explanation at #11641 but for me it's still confusing because it looks like it was chosen one logic for the beginning and another for the end (the ^x Indice) when it says in the example:
Index i1 = 3; // number 3 from beginning
Index i2 = ^4; // number 4 from end
"number 3 from beginning" sounds like "get the 3rd number from the beginning" as "number 4 from end" sounds like "take the fourth number counting from end".
I couldn't understand not because of the choice between inclusive and exclusive ranges, but why was it chosen to get the n-th element from begin using a 0-based index in an array (the usual) and not use the same logic the get the n-th element from the end.
@taxpayer Thanks for adding to the discussion here. I'll make sure to address your questions as part of the work on this issue.
If you'd like, I'll tag you in the PR so you can comment before it goes live.