-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
I'm confused. What does range[2..4] give me? From 2 to 4 (inclusive), which is 3 items? Or from 2 to 4 (exclusive), which is 2 to 3? Or from 2 on 4 items, which is 2 to 5? The description has very much text but nothing to find that could answer this simple question. The C# code editor tooltips and dropdowns don't even know what I'm doing here, explaining me that I'm typing a single byte offset number.
My problem is that I have this code: Encoding.ASCII.GetString(responseBody.Span[index..(index + length - 1)]) which should read length bytes starting at index but gives me one character less than length. When I still used the non-span code with buffer/offset/count, it worked and was clearly readable. Following these modern style suggestions caused me a lot of work (the range/memory stuff is just as viral as async/await) and now this problem.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: bcdddc9e-3060-4a72-95fa-93f8a4b6b741
- Version Independent ID: a70329e0-1d30-2e54-e8b8-22f9733bd09f
- Content: Ranges and indices - C# 8.0 draft specifications
- Content Source: proposals/csharp-8.0/ranges.md
- Product: dotnet-csharp
- Technology: csharp-spec
- GitHub Login: @dotnet-bot
- Microsoft Alias: wiwagn