Type of issue
Missing information
Description
In the following C# code snippet:
string second = names[1]; // 0-based index
string last = names[^1]; // ^1 is the last element
int[] smallNumbers = numbers[0..5]; // 0 to 4
the comment // 0 to 4 may be confusing because the numbers array values are also 1 through 10.
A reader could interpret the comment as referring to the values included in smallNumbers rather than the indexes used by the range expression.
Suggested improvement
Consider clarifying that the comment refers to indexes, for example:
int[] smallNumbers = numbers[0..5]; // indexes 0 through 4
or
int[] smallNumbers = numbers[0..5]; // elements at indexes 0-4
This would make the example easier to understand for readers who are new to range syntax.
Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/overview
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/tour-of-csharp/overview.md
Document Version Independent Id
ffae9ae1-d3f5-4192-0a18-ca475c712813
Platform Id
41a669fb-55ed-d212-8af3-4d212ac707a2
Article author
@BillWagner
Metadata
- ID: 85b00578-37d2-1fd1-911d-3097aa73f212
- PlatformId: 41a669fb-55ed-d212-8af3-4d212ac707a2
- Service: dotnet-csharp
- Sub-service: get-started
Related Issues
Type of issue
Missing information
Description
In the following C# code snippet:
string second = names[1]; // 0-based indexstring last = names[^1]; // ^1 is the last elementint[] smallNumbers = numbers[0..5]; // 0 to 4the comment
// 0 to 4may be confusing because thenumbersarray values are also 1 through 10.A reader could interpret the comment as referring to the values included in
smallNumbersrather than the indexes used by the range expression.Suggested improvement
Consider clarifying that the comment refers to indexes, for example:
int[] smallNumbers = numbers[0..5]; // indexes 0 through 4or
int[] smallNumbers = numbers[0..5]; // elements at indexes 0-4This would make the example easier to understand for readers who are new to range syntax.
Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/overview
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/tour-of-csharp/overview.md
Document Version Independent Id
ffae9ae1-d3f5-4192-0a18-ca475c712813
Platform Id
41a669fb-55ed-d212-8af3-4d212ac707a2
Article author
@BillWagner
Metadata
Related Issues