C# 8 added the ranges syntax to C#:
var slice = myArray[0..2];
What I find not so intuitive is that the upper bound (2
in the previous example) is exclusive - not inclusive; i.e. myArray[0..2]
returns a slice with 2 elements (0 and 1), not with 3 elements.
So my question is: Why did the C# language designers choose to make the upper bound exclusive?
Both the ranges documentation as well as the design champion issue simply state that the upper bound is exclusive - without giving any explanation as to why (at least none that I could find). There also was a discussion about this on GitHub but it also doesn't seem to contain any official explanation.
By searching StackOverflow I stumbled across the same question for Python. Python also treats the upper bound as exclusive. So I can imagine that the C# language designers were looking at other languages (that have ranges) and were trying to make C#'s behavior consistent with other languages. But I'm still wondering if there is any official documentation on this decision.